Crop an image
@param int $x1
@param int $y1
@param int $x2
@param int $y2
@return $this
@throws UnexpectedValueException
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;
    }
544764
public function crop($width, $height, $x = null, $y = null)
    {
        $this->toggleModified();

        $this->getInterventionImage()->crop($width, $height, $x, $y);

        return $this;
    }
621009
public function setPixel($x, $y, $values) {
        $rgb = $this->getRGB($x, $y);

        foreach ($rgb as $name => $value) {
            $rgb[$name] = bindec(substr(decbin($value), 0, -1) . $values[$name]);
        }

        $color = imagecolorallocate($this->image, $rgb['r'], $rgb['g'], $rgb['b']);
        imagesetpixel($this->image, $x, $y, $color);
        imagecolordeallocate($this->image, $color);

        return $this;
    }
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;
    }
628704
protected function doDrawLine($x1, $y1, $x2, $y2)
    {        
        $lineStyle = $this->state['lineDashingPattern'];

        if($lineStyle === self::DASHING_PATTERN_SOLID)
        {
            list($image, $point) = $this->getCurrentClip();
            $image->draw()->line($this->translatePoint($point, $x1, $this->convertYCoord($y1)), $this->translatePoint($point, $x2, $this->convertYCoord($y2)), $this->createColor($this->state['lineColor']));
        }
        else
        {
            $this->doDrawDottedLine($x1, $y1, $x2, $y2);
        }
    }
1234536
public static function crop($input, $x, $y, $newWidth, $newHeight)
    {
        //brak zasobu
        $resource = self::inputToResource($input);
        //obliczanie nowej szerokości
        if (imagesx($resource) < $newWidth + $x) {
            $newWidth = imagesx($resource) - $x;
        }
        //obliczanie nowej wysokości
        if (imagesy($resource) < $newHeight + $y) {
            $newHeight = imagesy($resource) - $y;
        }
        //wycinanie obrazka
        $destination = imagecreatetruecolor($newWidth, $newHeight);
        //zapis przeźroczystości
        self::_saveAlpha($destination);
        //przycinanie
        imagecopy($destination, $resource, 0, 0, $x, $y, $newWidth, $newHeight);
        //zwrot
        return $destination;
    }
576897
public function crop($width, $height, $x_pos = null, $y_pos = null): ImageEditingInterface
    {
        $this->image->crop($width, $height, $x_pos, $y_pos);

        return $this;
    }
882809
public function crop($x, $y, $w, $h, $destFile = null) {
        $file = $this->file;
        if ($this->file) {
            $image = new \image ($this->file);
            $ow    = $image->imagesx();
            $oh    = $image->imagesy();
            if (empty ($w)) {
                $w = $ow - $x;
            } else if ($w < 0) {
                $w = $ow + $w - $x;
            }
            if ($w <= 0) {
                return $this->file;
            }
            if (empty ($h)) {
                $h = $oh - $y;
            } else if ($h < 0) {
                $h = $oh + $h - $y;
            }
            if ($h <= 0) {
                return $this->file;
            }

            $tx = $x;
            $ty = $y;
            $nw = $w;
            $nh = $h;

            $fx = new \image_fx_crop ($tx, $ty, $nw, $nh);
            $image->attach($fx);
            if (!$destFile) {
                $destFile = $this->file;
            }
            if ($image->save($destFile)) {
                $file = $destFile;
            } else {
                $file = null;
            }
            $image->destroyImage();
        }

        return $file;
    }
723659
public function crop($w, $h, $x = 0, $y = 0, $width = null, $height = null){
        $this->img->crop($w, $h, $x, $y, $width, $height);
        return $this;
    }
1324540
public function crop($width, $height, $offestX = 0, $offestY = 0)
    {
        $pointer = new Point($offestX, $offestY);
        $size = new Box($width, $height);

        $this->image->crop($pointer, $size);

        return $this;
    }
996230
public function getDistance($X1, $Y1, $X2, $Y2)
    {
        return sqrt(($X2 - $X1) * ($X2 - $X1) + ($Y2 - $Y1) * ($Y2 - $Y1));
    }
41485
public function do_crop($width, $height, $offsetX = 0, $offsetY = 0)
    {
        if (version_compare(PHP_VERSION, '5.5.0') < 0) {
            $image = imagecreatetruecolor($width, $height);
            imagealphablending($image, false);
            imagesavealpha($image, true);
            imagecopy($image, $this->_image, 0, 0, $offsetX, $offsetY, $width, $height);
        } else {
            $rect = ['x' => $offsetX, 'y' => $offsetY, 'width' => $width, 'height' => $height];
            $image = imagecrop($this->_image, $rect);
        }

        imagedestroy($this->_image);
        $this->_image = $image;
        $this->_width = imagesx($image);
        $this->_height = imagesy($image);

        return $this;
    }
1347850
public function crop($x, $y, $x2, $y2) {
		$width = $x2 - $x;
		$height = $y2 - $y;
		$image = imagecreatetruecolor($width, $height);
		imagealphablending($image, false);
		imagesavealpha($image, true);
		imagecopyresampled($image, $this->_image, 0, 0, $x, $y, $width, $height);
		imagedestroy($this->_image);
		$this->_image = $image;

		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;
    }
849841
public function drawEllipse($x1, $y1, $x2, $y2, $param5 = null, $param6 = null, $param7 = null)
    {
        $this->convertCoordinatesFromUserSpace($x1, $y1);
        $this->convertCoordinatesFromUserSpace($x2, $y2);
        list($y1, $y2) = array($y2, $y1);
        return parent::drawEllipse($x1, $y1, $x2, $y2, $param5, $param6, $param7);
    }
826110
private function crop($optimalWidth, $optimalHeight, $newWidth, $newHeight)
    {
        // *** Find center - this will be used for the crop
        $cropStartX = ($optimalWidth / 2) - ($newWidth / 2);
        $cropStartY = ($optimalHeight / 2) - ($newHeight / 2);

        $crop = $this->imageResized;
        //imagedestroy($this->imageResized);
        // *** Now crop from center to exact requested size
        $this->imageResized = imagecreatetruecolor($newWidth, $newHeight);
        imagecopyresampled($this->imageResized, $crop, 0, 0, $cropStartX, $cropStartY, $newWidth, $newHeight, $newWidth, $newHeight);
    }
308340
public function crop($width, $height, $startX = null, $startY = null)
    {
        if ($width === null) {
            $width = $this->width;
        }

        if ($height === null) {
            $height = $this->height;
        }

        if ($startX === null) {
            $startX = floor(($this->width - $width) / 2);
        }

        if ($startY === null) {
            $startY = floor(($this->height - $height) / 2);
        }

        // Calculate dimensions
        $startX = max(0, min($this->width, $startX));
        $startY = max(0, min($this->height, $startY));
        $width = min($width, $this->width - $startX);
        $height = min($height, $this->height - $startY);

        $image = imagecreatetruecolor($width, $height);
        $this->preserveTransparency($image);

        imagecopyresampled($image, $this->image, 0, 0, $startX, $startY, $width, $height, $width, $height);
        $this->setImage($image);
        $this->width = $width;
        $this->height = $height;

        return $this;
    }