rtadams89 Posted June 16, 2009 Share Posted June 16, 2009 As part of my web gallery, I have a script which generates thumbnails from uploaded pictures. The uploaded pictures vary in dimensions from portrait to landscape. I want all the thumbnails to be exactly 100 x 66 pixels, and contain no white space or "filler." Additionally, I want to maintain the aspect ratio of the original image. Obviously, this means some cropping will occur with images that don't have a 100/66 aspect ratio. I'm familiar with PHP, but not with the GD library, so I've been looking at example scripts to do this. I've found plenty that will create 100 x 66 thumbnails, but they all seem to either distort the aspect ratio to make the picture fit or include white space to pad the image. I have yet to find one that will properly crop and re size any image I throw at it to produce a thumbnail with as much of the original image as possible, while maintaining the aspect ratio. Can anyone point me to such a script? Link to comment https://forums.phpfreaks.com/topic/162334-solved-issues-cropping-thumbnails-to-maintain-aspect-ratio/ Share on other sites More sharing options...
ict_ashley Posted June 16, 2009 Share Posted June 16, 2009 Shouldn't be a problem, just calculate what height the "scaled down" version will be when width=100. If it's smaller than 66 then you need to scale the image to height=66 and then crop it using something like: <?php $src = imagecreatefromjpg('gallery_image.jpg'); $size = getimagesize('gallery_image.jpg'); $dest = imagecreatetruecolor(100, 66); imagecopy($dest, $src, 0, 0, 100, 66, $size[0], $size[1]); ?> Link to comment https://forums.phpfreaks.com/topic/162334-solved-issues-cropping-thumbnails-to-maintain-aspect-ratio/#findComment-856832 Share on other sites More sharing options...
rtadams89 Posted June 16, 2009 Author Share Posted June 16, 2009 I finally got it working. Very simple once I managed to get the numbers straight in my head. Link to comment https://forums.phpfreaks.com/topic/162334-solved-issues-cropping-thumbnails-to-maintain-aspect-ratio/#findComment-856917 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.