PHP GD - How can I modify my Thumbnail Creator to crop portrait images from the center?
- by frank
Here is my current code:
$image = 'img.jpg';
$source = imagecreatefromjpeg($image);
list($origWidth, $origHeight) = getimagesize($image);
$imgH = 75;
$imgW = $origWidth / $origHeight * $imgH;
$thumb = imagecreatetruecolor($imgW, $imgH);
imagecopyresampled($thumb, $source, 0, 0, 0, 0, $imgW, $imgH, $origWidth, $origHeight);
This allows me to output an image with a fixed height of 75 pixels. What I would like to do is have a constant image size of 99x75 pixels. Portrait images that don't fit into this will be cropped from the center (so the center of the original remains the center of the thumbnail - if that makes sense).
How can I do this?