Image::crop PHP Method

crop() public method

public crop ( $top_x, $top_y, $bottom_x, $bottom_y )
    public function crop($top_x, $top_y, $bottom_x, $bottom_y)
    {
        $image_old = $this->image;
        $this->image = imagecreatetruecolor($bottom_x - $top_x, $bottom_y - $top_y);
        imagecopy($this->image, $image_old, 0, 0, $top_x, $top_y, $this->width, $this->height);
        imagedestroy($image_old);
        $this->width = $bottom_x - $top_x;
        $this->height = $bottom_y - $top_y;
    }

Usage Example

		static public function imageResize($fname,$width,$height) {
			$i = new Image( $fname );
			$owhr=$i->getWidth()/$i->getHeight();
			$twhr=$width/$height;
			if( $owhr==$twhr )	{
				$i->resize( $width,$height );
			}	elseif( $owhr>$twhr )	{
				$i->resizeToHeight( $height );
				$i->crop( ($i->getWidth()-$width)/2, 0, $width, $height);
			}	else	{
				$i->resizeToWidth( $width );
				$i->crop( 0, ($i->getHeight()-$height)/2, $width, $height);
			}
			$i->save();
		}
All Usage Examples Of Image::crop