Crops a portion of the image.

@param int $width  The width.
@param int $height The height.
@param int $coordX The X coordinate.
@param int $coordY The Y coordinate.

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

        return $this;
    }
1259495
private function actionResize($width, $height)
    {
        $image = $this->getPhpThumb();
        $image->resize($width, $height);
    }
1216151
public function resize($width, $height)
    {
        $width = (int)$width;
        $height = (int)$height;
        $tmpImage = imagecreatetruecolor($width, $height);
        imagefilledrectangle($tmpImage, 0, 0, $width, $height, $this->backgroundColor);
        imagecopyresampled($tmpImage, $this->resource, 0, 0, 0, 0, $width, $height, $this->width, $this->height);
        $this->width = $width;
        $this->height = $height;
        $this->resource = $tmpImage;
    }
693954
public function resize($width, $height) {
		$image = imagecreatetruecolor($width, $height);
		imagecopyresampled($image, $this->_image, 0, 0, 0, 0, $width, $height, $this->width, $this->height);
		imagedestroy($this->_image);
		$this->_image = $image;
		return $this;
	}
214397
public function pad($width, $height, $options) {
        if (!$height || !$width) throw new Exception('Croppa: Pad option needs width and height');
        $color = $options['pad'] ?: [255, 255, 255];
        $this->thumb->resize($width, $height)->pad($width, $height, $color);
        return $this;
    }
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;
    }
946516
protected function resizeCrop($file, $width, $height)
  	{
		$image = $this->imagine->open($file->getRealPath());
		list($optimalWidth, $optimalHeight) = $this->getOptimalCrop($image->getSize(), $width, $height);

    	// Find center - this will be used for the crop
		$centerX = ($optimalWidth / 2) - ($width / 2);
    	$centerY = ($optimalHeight / 2) - ($height / 2);

		return $image->resize(new Box($optimalWidth, $optimalHeight))
			->crop(new Point($centerX, $centerY), new Box($width, $height));
	}
1051075
public function resize($width, $height)
    {
        $newImage = imagecreatetruecolor($width, $height);

        $this->strategy->handleTransparency($newImage, $this->image);

        // Now resample the image
        imagecopyresampled($newImage, $this->image, 0, 0, 0, 0, $width, $height, $this->getWidth(), $this->getHeight());

        // And allocate to $this
        $this->image = $newImage;
    }
1330410
private function crop($file, array $coords, array $options)
    {
        if (isset($options['width']) && !isset($options['height'])) {
            $width = $options['width'];
            $height = $options['width'] * $coords['h'] / $coords['w'];
        } elseif (!isset($options['width']) && isset($options['height'])) {
            $width = $options['height'] * $coords['w'] / $coords['h'];
            $height = $options['height'];
        } elseif (isset($options['width']) && isset($options['height'])) {
            $width = $options['width'];
            $height = $options['height'];
        } else {
            $width = $coords['w'];
            $height = $coords['h'];
        }

        return Image::crop($file->tempName, $coords['w'], $coords['h'], [$coords['x'], $coords['y']])
            ->resize(new Box($width, $height));
    }
157131
public function setResolution($width, $height)
    {
        $this->width = $width;
        $this->height = $height;
        return $this;
    }
52234
public function crop($width, $height, $gravity, $background = null)
    {
        $this->mode = 'crop';
        $this->targetSize = [$width, $height];
        $this->arguments = [$gravity, $background];

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

        return $this->process();
    }
768524
public function do_crop($width, $height, $offsetX = 0, $offsetY = 0)
    {
        $this->_image->cropImage($width, $height, $offsetX, $offsetY);
        $this->_image->setImagePage($width, $height, 0, 0);

        $this->_width = $this->_image->getImageWidth();
        $this->_height = $this->_image->getImageHeight();

        return $this;
    }
919512
public function resizeCropCenter($width, $height)
    {
        $_width = $this->do_getWidth();
        $_height = $this->do_getHeight();

        if ($_width / $_height > $width / $height) {
            $crop_height = $_height;
            $crop_width = $width * $crop_height / $height;
            $offsetX = ($_width - $crop_width) / 2;
            $offsetY = 0;
        } else {
            $crop_width = $_width;
            $crop_height = $height * $crop_width / $width;
            $offsetY = ($_height - $crop_height) / 2;
            $offsetX = 0;
        }

        $this->crop($crop_width, $crop_height, $offsetX, $offsetY);
        $this->scale($width / $crop_width);

        return $this;
    }
814953
protected function extent($width, $height, $flag = '')
    {
        extract(
            $this->getCropCoordinates(
                $this->resource->getImageWidth(),
                $this->resource->getImageHeight(),
                $width,
                $height,
                $this->resource->getGravity()
            )
        );

        $this->resource->extentImage($width, $height, $x, $y);
        return $this;
    }
617878
protected function createCropPoint(AbstractImage $abstractImage, $width, $height)
    {
        if (!is_numeric($width) || !is_numeric($height)) {
            throw new \LogicException('Provided values for width and height are not numeric!');
        }

        $width = (int) $width;
        $height = (int) $height;

        $imageWidth = $abstractImage->getSize()
            ->getWidth();
        $imageHeight = $abstractImage->getSize()
            ->getHeight();

        if ($imageWidth < $width || $imageHeight < $height) {
            throw new ImageTooSmallException('Provided image is too small to be resize! Provide larger image.');
        }

        $cropWidth = ($imageWidth / 2) - ($width / 2);
        $cropHeight = ($imageHeight / 2) - ($height / 2);

        $box = clone $this->box;
        $box->setWidth(round($cropWidth))
            ->setHeight(round($cropHeight));
        $this->point->setBox($box);

        return $this->point;
    }