note 121792 deleted from function.imagecrop by cmb
| From: | cmb@php.net | Date: | Fri, 09 Oct 2020 12:33:59 +0000 |
| Subject: | note 121792 deleted from function.imagecrop by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-215560@lists.php.net to get a copy of this message | ||
Note Submitter: vanadragos at yahoo dot com
----
To get the center crop of a image in php:
$new = imagecreatefromjpeg($uploadedfile);
$crop_width = imagesx($new);
$crop_height = imagesy($new);
$size = min($crop_width, $crop_height);
if($crop_width >= $crop_height) {
$newx= ($crop_width-$crop_height)/2;
$im2 = imagecrop($new, ['x' => $newx, 'y' => 0, 'width' =>
$size, 'height' => $size]);
}
else {
$newy= ($crop_height-$crop_width)/2;
$im2 = imagecrop($new, ['x' => 0, 'y' => $newy, 'width'
=> $size, 'height' => $size]);
}
imagejpeg($im2,$filename,90);