Vanilla Cropping - Crops from x,y with specified width and height

@param int $startX
@param int $startY
@param int $cropWidth
@param int $cropHeight
@return GdThumb
776597
public function crop ($startX, $startY, $cropWidth, $cropHeight)
	{
		// validate input
		if (!is_numeric($startX))
		{
			throw new InvalidArgumentException('$startX must be numeric');
		}
		
		if (!is_numeric($startY))
		{
			throw new InvalidArgumentException('$startY must be numeric');
		}
		
		if (!is_numeric($cropWidth))
		{
			throw new InvalidArgumentException('$cropWidth must be numeric');
		}
		
		if (!is_numeric($cropHeight))
		{
			throw new InvalidArgumentException('$cropHeight must be numeric');
		}
		
		// do some calculations
		$cropWidth	= ($this->currentDimensions['width'] < $cropWidth) ? $this->currentDimensions['width'] : $cropWidth;
		$cropHeight = ($this->currentDimensions['height'] < $cropHeight) ? $this->currentDimensions['height'] : $cropHeight;
		
		// ensure everything's in bounds
		if (($startX + $cropWidth) > $this->currentDimensions['width'])
		{
			$startX = ($this->currentDimensions['width'] - $cropWidth);
			
		}
		
		if (($startY + $cropHeight) > $this->currentDimensions['height'])
		{
			$startY = ($this->currentDimensions['height'] - $cropHeight);
		}
		
		if ($startX < 0) 
		{
			$startX = 0;
		}
		
	    if ($startY < 0) 
		{
			$startY = 0;
		}
		
		// create the working image
		if (function_exists('imagecreatetruecolor'))
		{
			$this->workingImage = imagecreatetruecolor($cropWidth, $cropHeight);
		}
		else
		{
			$this->workingImage = imagecreate($cropWidth, $cropHeight);
		}
		
		$this->preserveAlpha();
		
		imagecopyresampled
		(
			$this->workingImage,
			$this->oldImage,
			0,
			0,
			$startX,
			$startY,
			$cropWidth,
			$cropHeight,
			$cropWidth,
			$cropHeight
		);
		
		$this->oldImage 					= $this->workingImage;
		$this->currentDimensions['width'] 	= $cropWidth;
		$this->currentDimensions['height'] 	= $cropHeight;
		
		return $this;
	}
1167238
public function resizeAndCrop($targetWidth, $targetHeight)
    {
        if ($this->getAutoOrient()) {
            $this->autoOrient();
        }

        // First get the size that we can use to safely trim down the image without cropping any sides
        $crop = $this->getSafeResizeOffset($this->originalImage, $targetWidth, $targetHeight);
        // Resize the image
        $this->originalImage->resizeImage($crop['width'], $crop['height'], $this->getFilter(), $this->getBlur());
        // Get the offset for cropping the image further
        $offset = $this->getSpecialOffset($this->originalImage, $targetWidth, $targetHeight);
        // Crop the image
        $this->originalImage->cropImage($targetWidth, $targetHeight, $offset['x'], $offset['y']);

        return $this->originalImage;
    }
549088
public function crop($width, $height, $coordX, $coordY)
    {
        $this->resource->crop($width, $height, $coordX, $coordY);

        return $this;
    }
515354
public function crop($x1, $y1, $x2, $y2)
    {
        if ($x2 < $x1) {
            list($x1, $x2) = array($x2, $x1);
        }
        if ($y2 < $y1) {
            list($y1, $y2) = array($y2, $y1);
        }

        $crop_width = $x2 - $x1;
        $crop_height = $y2 - $y1;

        $new = imagecreatetruecolor($crop_width, $crop_height);

        if (empty($new)) {
            throw new UnexpectedValueException('Failed to create an image identifier');
        }

        imagealphablending($new, false);
        imagesavealpha($new, true);

        if (!imagecopyresampled($new, $this->image, 0, 0, $x1, $y1, $crop_width, $crop_height, $crop_width, $crop_height)) {
            throw new UnexpectedValueException('Failed to copy and resize part of an image with resampling');
        }

        $this->image = $new;
        $this->width = $crop_width;
        $this->height = $crop_height;

        return $this;
    }
513379
def create_crop(self, name, x, x2, y, y2):
        
        if self._can_crop():
            spec = get_image_cropper().create_crop(name, self.file, x=x,
                                                   x2=x2, y=y, y2=y2)
            ImageDetail.save_crop_spec(self, spec)
712065
def random_crop(src, size):
    """"""
    h, w, _ = src.shape
    new_w, new_h = scale_down((w, h), size)

    x0 = random.randint(0, w - new_w)
    y0 = random.randint(0, h - new_h)

    out = fixed_crop(src, x0, y0, new_w, new_h, size)
    return out, (x0, y0, new_w, new_h)
1109089
public function cropToFit($width, $height, $focusPointX = 0, $focusPointY = 0)
    {

        $debug = $width == 100 && $height == 100;

        // Check if the image is a valid resource
        if (!is_resource($this->image)) {
            throw new RuntimeException('No image set');
        }

        // Get the width and height of element
        $originalWidth = imagesx( $this->image );
        $originalHeight = imagesy( $this->image );

        // Check if any of the width and height is null, and set it to the $source size
        $width = $width ?: $originalWidth;
        $height = $height ?: $originalHeight;

        // Calculate the aspect ratio of the existing image
        $originalAspectRatio = $originalWidth / $originalHeight;

        // Calculate the aspect ratio of the desired image
        $desiredAspectRatio = $width / $height;

        // Check what value we should use with the aspect ratio
        if ( $originalAspectRatio > $desiredAspectRatio ) {
            $temp_height = $height;
            $temp_width = ( int ) ($height * $originalAspectRatio);
        }
        else {
            $temp_width = $width;
            $temp_height = ( int ) ($width / $originalAspectRatio);
        }

        // Get the center of image based on the focusPoint
        $x0 = ( $temp_width - $width ) * ( ( $focusPointX + 1 ) * .5 );
        $y0 = ( $temp_height - $height ) * ( ( $focusPointY + 1 ) * .5 );

        // If $x0 or $y0 is not a full number increase with one pixel
        // to fill black line and fill canvas
        if ( ! ctype_digit( $x0 ) || ! ctype_digit( $y0 ) ) {
            $temp_width++;
            $temp_height++;
        }

        // Resize the image into the desired image
        $this->resize( $temp_width, $temp_height );

        // Create canvas for the new image
        $canvas = $this->createCanvas( $width, $height );
        // Do the cropping of image
        imagecopy( $canvas, $this->image, 0, 0, $x0, $y0, $width, $height );

        // Replace the image
        $this->replace( $canvas );

        // Return $this for chaining
        return $this;
    }
471312
public static int Maximum(ImageSource fastBitmap, int startX, int startY, int width, int height) {
        int max = 0;

        if (fastBitmap.isGrayscale()) {
            for (int i = startX; i < height; i++) {
                for (int j = startY; j < width; j++) {
                    int gray = fastBitmap.getRGB(j, i);
                    if (gray > max) {
                        max = gray;
                    }
                }
            }
        } else {
            for (int i = startX; i < height; i++) {
                for (int j = startY; j < width; j++) {
                    int gray = fastBitmap.getG(j, i);
                    if (gray > max) {
                        max = gray;
                    }
                }
            }
        }

        return max;
    }
949853
protected function do_crop(\stdClass $src, $top, $left, $bottom, $right) {

		$src->resource->cropImage($src->width - $right - $left, $src->height - $bottom - $top, $left, $top);

		$src->width		= $src->width - $right - $left;
		$src->height	= $src->height - $bottom - $top;

		return $src;

	}
677196
public function cropAndResize($width, $height, $gravity)
    {
        $this->mode = 'cropResize';
        $this->targetSize = [$width, $height];
        $this->arguments = [$gravity];

        return $this->process();
    }
859561
public function crop($top, $left, $width, $height)
    {
        return $this->createCloneWithResource(
            function (InterventionImage $resource) use ($top, $left, $height, $width) {
                return $resource->crop($width, $height, $left, $top);
            }
        );
    }
239626
def _cropbox(self, image, x, y, x2, y2):
        
        image['options']['crop'] = '%sx%s+%s+%s' % (x2 - x, y2 - y, x, y)
        image['size'] = (x2 - x, y2 - y)  # update image size
        return image
808327
public function crop($x, $y, $width, $height, $interlace = false) {
		return $this -> createImage($x, $y, $width, $height, $width, $height, $interlace);
	}
1186223
public function crop($width, $height, $offsetX = 0, $offsetY = 0)
    {
        $this->do_crop($width, $height, $offsetX, $offsetY);

        return $this;
    }
1220509
public ImageHandlerBuilder crop(int x, int y, int width, int height) {
         height = Math.min(height, image.getHeight() - y); 
         width = Math.min(width, image.getWidth() - x);

         BufferedImage crop = Scalr.crop(image, x, y, width, height);
         image.flush();// cannot throw
         image = crop;
         return this;
     }
608590
public function focalCrop(int $width, int $height, int $focalX, int $focalY)
    {
        $this->width($width);
        $this->height($height);

        return $this->addManipulation('crop', "crop-{$focalX}-{$focalY}");
    }
191612
public function crop($w, $h, $x = 0, $y = 0, $width = null, $height = null)
    {
        //设置保存尺寸
        empty($width) && $width   = $w;
        empty($height) && $height = $h;
        do {
            //创建新图像
            $img = imagecreatetruecolor($width, $height);
            // 调整默认颜色
            $color = imagecolorallocate($img, 255, 255, 255);
            imagefill($img, 0, 0, $color);
            //裁剪
            imagecopyresampled($img, $this->im, 0, 0, $x, $y, $width, $height, $w, $h);
            imagedestroy($this->im); //销毁原图
            //设置新图像
            $this->im = $img;
        } while (!empty($this->gif) && $this->gifNext());
        $this->info['width']  = (int) $width;
        $this->info['height'] = (int) $height;
        return $this;
    }