this method crops the image
@param Array $crop crop config
@param \Imagine\Gd\Image $image
493877
protected function createCrop($crop, $image)
	{
		if (!empty($crop['cropped_field'])) {
			$save_path = $this->getUploadPath($crop['cropped_field']);
		} else {
			$save_path = $this->getUploadPath($this->attribute);
		}

		$sizes = explode('-', $crop['value']);

		$real_size = $image->getSize();

		foreach ($sizes as $ind => $cr) {
			$sizes[$ind] = round($sizes[$ind]*($ind%2 == 0 ? $real_size->getWidth() : $real_size->getHeight())/100);
		}

		$crop_image = $image->crop(new Point($sizes[0], $sizes[1]), new Box($sizes[2]-$sizes[0], $sizes[3]-$sizes[1]));

		if (!empty($crop['crop_width']))
			$crop_image = $crop_image->resize(new Box($crop['crop_width'], $crop['crop_width'] / $crop['ratio']));

		$crop_image->save($save_path, isset($crop['save_options']) ? $crop['save_options'] : $this->save_options);
	}
1039520
private function _paintCanvas(&$image) {
        if ($this->_params['type'] === IMAGETYPE_JPEG) {
            if (!$this->_params['crop']
                || !$this->_params['grow']
            ) {
                $this->_paintCanvasOpaque($image);
            }
        } else {
            $this->_paintCanvasTransparent($image);
        }
    }
865183
public function crop() {

		$args = func_get_args();
		
		$srcAspectRatio = $this->srcWidth / $this->srcHeight;
		
		// single float value given, represents aspect ratio of cropped image

		if(count($args) === 1) {

			if(!is_numeric($args[0]) || $args[0] <= 0) {
				throw new ImageModifierException('Invalid dimension(s) for cropping: ' . $args[0] . '.');
			}
		
			if($srcAspectRatio <= $args[0]) {
		
				// width determines

				$left = $right = 0;

				if($srcAspectRatio >= 1) {

				    // assume landscape

                    $top = $bottom = round(($this->srcHeight - $this->srcWidth / $args[0]) / 2);

                }

				else {

				    // assume portrait and shift crop somewhat up

                    $top = round(($this->srcHeight - $this->srcWidth / $args[0]) / 3);
                    $bottom	= round(($this->srcHeight - $this->srcWidth / $args[0]) * 2 / 3);

                }
			}

			else {
		
				// height determines

				$top = $bottom = 0;
				$left = $right = round(($this->srcWidth - $this->srcHeight * $args[0]) / 2);
			}
		}
		
		// width and height given
		
		else if(count($args) === 2) {

			$width	= (int) $args[0];
			$height	= (int) $args[1];
		
			if($width > 0 && $height > 0) {
				$left = $right = round(($this->srcWidth - $width) / 2);
		
				if($srcAspectRatio >= 1) {

					// landscape

					$top = $bottom = round(($this->srcHeight - $height) / 2);
				}

				else {

					// portrait and shift crop up

					$top	= round(($this->srcHeight - $height) / 3);
					$bottom	= round(($this->srcHeight - $height) * 2 / 3);
				}
			}
		
			else {
				throw new ImageModifierException('Invalid dimension(s) for cropping: ' . $width . ', ' . $height . '.');
			}
		}
		
		// top, left, bottom, right
		
		else if(count($args) == 4) {

			$top	= (int) $args[0];
			$left	= (int) $args[1];
			$bottom	= (int) $args[2];
			$right	= (int) $args[3];

		}

		else {
			throw new ImageModifierException('Insufficient arguments for cropping.');
		}
		
		// skip queuing when there is nothing to crop
		
		if(!$top && !$bottom && !$left && !$right) {

			return;

		}

		$todo = new \stdClass();
		
		$todo->method		= __FUNCTION__;
		$todo->parameters	= array($top, $right, $bottom, $left);

		$this->queue[] = $todo;
		
		$this->srcWidth		= $this->srcWidth - $left - $right;
		$this->srcHeight	= $this->srcHeight - $top - $bottom;

	}
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;
    }
1118574
public function crop( $x, $y, $width, $height )
	{
		// check for auto
		if ( $x == 'center' || $x == 'auto' )
		{
			$x = ( $this->width / 2 ) - ( $width / 2 );
		}

		if ( $y == 'middle' || $y == 'auto' )
		{
			$y = ( $this->height / 2 ) - ( $height / 2 );
		}

		$result = imagecreatetruecolor( $width, $height );  
		ImageCopyResampled( $result, $this->image_context, 0, 0, $x, $y, $width, $height, $width, $height );

		$this->image_context = $result;

		// update properties
		$this->reload_context_info();

		// return self
		return $this;
	}
410615
public function setPreviewCrop($crop)
	{
		$this->isModified = true;
		$this->parameters['preview_crop'] = (bool) $crop;

		return $this;
	}
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;

	}
644463
public function cropFromEdge($cropWidth, $cropHeight = null, $edge = 0)
        {
            if ($cropHeight === null) {
                $cropHeight = $cropWidth;
            }

            $cropWidth = ($this->_sourceWidth < $cropWidth) ? $this->_sourceWidth:$cropWidth;
            $cropHeight = ($this->_sourceHeight < $cropHeight) ? $this->_sourceHeight:$cropHeight;

            $cropX = intval(($this->_sourceWidth - $cropWidth) / 2);
            $cropY = intval(($this->_sourceHeight - $cropHeight) / 2);

            $top = (int) $edge | 12;
            if (14 == $top) {
                $cropY = 0;
            } elseif (13 == $top) {
                $cropY = $this->_sourceHeight - $cropHeight;
            }

            $left = ($edge >> 2);
            if (2 == $left) {
                $cropX = 0;
            } elseif (1 == $left) {
                $cropX = $this->_sourceWidth - $cropWidth;
            }

            return $this->crop($cropX, $cropY, $cropWidth, $cropHeight);
        }
424503
public function resize($crop = false)
    {
        if ($crop) {
            return $this->resizeCrop();
        } else {
            $sourceDimension = $this->sourceImageFile->getDimension();
            $resampleDimension = $this->resampleImageFile->getDimension();

            if (($sourceDimension->getWidth() <= $resampleDimension->getWidth()) && ($sourceDimension->getHeight() <= $resampleDimension->getHeight())) {
                return true;
            } //no resizing needed

            //try max width first...
            $resizeRatio = $resampleDimension->getWidth() / $sourceDimension->getWidth();
            $resizeWidth = $resampleDimension->getWidth();
            $resizeHeight = $sourceDimension->getHeight() * $resizeRatio;

            //if that didn't work
            if ($resizeHeight > $resampleDimension->getHeight()) {
                $resizeRatio = $resampleDimension->getHeight() / $sourceDimension->getHeight();
                $resizeHeight = $resampleDimension->getHeight();
                $resizeWidth = $sourceDimension->getWidth() * $resizeRatio;
            }

            $resampleImageResource =& $this->getResampleImageResource();

            return $resampleImageResource->resizeImage(
                $resizeWidth,
                $resizeHeight,
                \Imagick::FILTER_CATROM, 0.9, true);
        }
    }
476454
def crop(self, image, size, crop, options):
        
        if not crop:
            return image
        return self.engine_crop(image, size, crop, options)
1330275
function crop($c_width, $c_height, $pos = 'center')
    {
        $new_width = $c_width;
        $new_height = $c_height;

        // Calcula el alto en base al nuevo ancho
        $t_height = ($new_width * $this->height) / $this->width;

        // Calcula el ancho en base al nuevo alto
        $t_width = ($new_height * $this->width) / $this->height;

        if($t_width >= $new_width)
        {
            $new_width = $t_width;
        }
        else
        {
            $new_height = $t_height;
        }

        $image = imagecreatetruecolor( $new_width, $new_height );
        imagecopyresampled($image, $this->image, 0, 0, 0, 0, $new_width, $new_height, $this->width, $this->height);

        $this->width = imagesx($image);
        $this->height = imagesy($image);
        $this->image = $image;

        //---Crear la imagen tomando la porción del centro de la imagen redimensionada con las dimensiones deseadas
        $image = imagecreatetruecolor($c_width, $c_height);

        switch($pos)
        {
            case 'center':
                imagecopyresampled($image, $this->image, 0, 0, abs(($this->width - $c_width) / 2), abs(($this->height - $c_height) / 2), $c_width, $c_height, $c_width, $c_height);
                break;

            case 'left':
                imagecopyresampled($image, $this->image, 0, 0, 0, abs(($this->height - $c_height) / 2), $c_width, $c_height, $c_width, $c_height);
                break;

            case 'right':
                imagecopyresampled($image, $this->image, 0, 0, $this->width - $c_width, abs(($this->height - $c_height) / 2), $c_width, $c_height, $c_width, $c_height);
                break;

            case 'top':
                imagecopyresampled($image, $this->image, 0, 0, abs(($this->width - $c_width) / 2), 0, $c_width, $c_height, $c_width, $c_height);
                break;

            case 'bottom':
                imagecopyresampled($image, $this->image, 0, 0, abs(($this->width - $c_width) / 2), $this->height - $c_height, $c_width, $c_height, $c_width, $c_height);
                break;
        }

        $this->image = $image;
    }
135836
function cropImage( $imageObject, $filterData, &$filterVariables, $sourceMimeData, $destinationMimeData )
    {
        $width = $filterData['data'][0];
        $height = $filterData['data'][1];
        $x = $filterData['data'][2];
        $y = $filterData['data'][3];
        $imageWidth = ImageSX( $imageObject );
        $imageHeight = ImageSY( $imageObject );
        $width = max( min( $width, $imageWidth - $x ), 0 );
        $height = max( min( $height, $imageHeight - $y ), 0 );
        $destinationGeometry = $this->createGeometry( $width, $height, 0, 0 );
        $geometry = $this->createGeometry( $width, $height, $x, $y );
        return $this->imageCopy( $imageObject,
                                 $destinationGeometry,
                                 $geometry,
                                 $sourceMimeData, $destinationMimeData );
    }
512077
public function crop(array $rectangle) {
        $croppedImage = @imagecrop($this->resource, $rectangle);
        if($croppedImage === false) {
            $rectangleAsString = "{";
            foreach($rectangle as $key => $value) {
                $rectangleAsString .= "\"{$key}\" => {$value}, ";
            }
            $rectangleAsString = preg_replace("/, $/", "}", $rectangleAsString);
            throw new ImageException(
                "Can not crop image {$this} via rectangle {$rectangleAsString}.",
                ImageException::GenericException
            );
        }
        $this->resource = $croppedImage;
        $this->width = $rectangle["width"];
        $this->height = $rectangle["height"];
    }
1168956
function (crop) {
            var pvDiv = document.getElementById(this._image.id + '_' + crop.id);
            if (pvDiv == null || typeof pvDiv != 'object') {
                return;
            }

            var pvDivInner = pvDiv.getElementsByTagName('DIV')[0]
            var pvImg = pvDiv.getElementsByTagName('IMG')[0];
            var previewHeight = window.getComputedStyle(pvDivInner).height.slice(0, -2)
            var imgDim = this._image.getDimensions();

            var previewWidth = IMSoftcrop.Ratio.width(previewHeight, crop.ratio.f);
            pvDivInner.style.width = previewWidth + 'px';

            var cropDim = crop.getDimensions();
            var cropRatio = previewWidth / cropDim.w;

            pvImg.style.height = imgDim.h * cropRatio + 'px';
            pvImg.style.marginTop = '-' + cropDim.y * cropRatio + 'px';
            pvImg.style.marginLeft = '-' + cropDim.x * cropRatio + 'px';

            if (crop.autoCropWarning == true) {
                pvDiv.classList.add('warning');
            }
            else {
                pvDiv.classList.remove('warning');
            }

            if (crop.usable == true) {
                pvDiv.classList.add('usable');
                pvDiv.classList.remove('unusable');
            }
            else {
                pvDiv.classList.add('unusable');
                pvDiv.classList.remove('usable');
            }
        }
415242
private function getAdjustedImageDimensions(Image $image, int $width, int $height, bool $crop = false): array
    {
        if ($image->getWidth() / $image->getHeight() > $width / $height) {		// current is wider than new
            if (true === $crop) {	// upscale prevention
                return [
                    'width' => $this->getImageWidth($image, $height),
                    'height' => $height,
                ];
            } else {
                return [
                    'width' => $width,
                    'height' => $this->getImageHeight($image, $width),
                ];
            }
        } elseif ($image->getWidth() / $image->getHeight() < $width / $height) {	// current is taller than new
            if (true === $crop) {	// upscale prevention
                return [
                    'width' => $width,
                    'height' => $this->getImageHeight($image, $width),
                ];
            } else {
                return [
                    'width' => $this->getImageWidth($image, $height),
                    'height' => $height,
                ];
            }
        } else {									// current has same aspect ratio as new
            return [
                'width' => $width,
                'height' => $height,
            ];
        }
    }
232633
public function cropImage(Image $image, int $width, int $height): Image
    {
        if (true === $image->getEncrypted()) {
            $this->decryptImage($image);
            $encrypt = true;
        } else {
            $encrypt = false;
        }

        $crop = $this->getAdjustedImageCropDimensions($image, $width, $height);
        $centerX = ($image->getWidth() / 2) - ($crop['width'] / 2);
        $centerY = ($image->getHeight() / 2) - ($crop['height'] / 2);
        $tmp = new Image($this->secret, null, $image->getExtension(), $this->autorotate);
        $tmp->create($width, $height);
        imagecopyresampled(
            $tmp->getData(),
            $image->getData(),
            0,
            0,
            (int)$centerX,
            (int)$centerY,
            $width,
            $height,
            $crop['width'],
            $crop['height']
        );
        $image->destroy();
        $image = $tmp;

        if (true === $encrypt) {
            $image = $this->encryptImage($image);
        }
        return $image;
    }
44273
public function cropImage(Image $file, $left, $top, $width, $height, $quality = 95)
	{
		if ( ! $file instanceof Image) {
			throw new Exception\RuntimeException('Image entity expected');
		}

		$filename = $this->getFilesystemPath($file);
		$cropper = $this->getImageCropper();
		$cropper->setSourceFile($filename)
				->setOutputFile($filename)
				->setOutputQuality($quality)
				->setLeft($left)
				->setTop($top)
				->setWidth($width)
				->setHeight($height);
		$cropper->process();

		$file->setWidth($width);
		$file->setHeight($height);

		$entityManager = $this->getDoctrineEntityManager();
		$entityManager->persist($file);
		$entityManager->flush();

		$this->recreateImageSizes($file);
	}