<?php
$file = '/var/www/examples/heroine.png';
$size = getimagesize($file);
$im = imagecreatefrompng($file);
$imf = imagecrop($im, ['x' => 50, 'y' => 50, 'width' => 600, 'height' => 300]);
imagePng($imf, '/tmp/image.png');
/var/www/examples/heroine.png
- path to image to cropgetimagesize
- returns image size from given pathimagecreatefrompng
- creates lib:GD image object from given PNG imageimagecrop
- crops given image'x' => 50, 'y' => 50
- top left point to start crop on'width' => 600, 'height' => 300
- size of cropping rectangleimagePng
- saves image in PNG format to the given path
<?php
$file = '/var/www/examples/heroine.png';
$size = getimagesize($file);
$im = imagecreatefrompng($file);
$imf = imagecrop($im, ['x' => 50, 'y' => 50, 'width' => 600, 'height' => 300]);
imagePng($imf, '/tmp/image.png');