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;
    }
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;
    }
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 ; }
Crops an image

@param integer $width
@param integer $height
@param integer $starX X offset
@param integer $starY Y offset
@return \Krystal\Image\Processor\GD\ImageProcessor
Crops an image