acctman Posted January 30, 2009 Share Posted January 30, 2009 I'd like to create a 75 x 75 thumbnail from images of various width and height. the goal is to make sure the thumbnail at 75 x 75 does not stretch, shrink or distort the image in any way. A great example is flickr... 75 x 75 thumbnail : http://farm4.static.flickr.com/3153/2538167690_c812461b7b_s.jpg large image: http://farm4.static.flickr.com/3153/2538167690_c812461b7b.jpg another example 75 x 75 thumbnail : http://farm3.static.flickr.com/2093/2538168854_f75e408156_s.jpg large image: http://farm3.static.flickr.com/2093/2538168854_f75e408156.jpg thanks in advance for the help Link to comment https://forums.phpfreaks.com/topic/143189-creating-the-perfect-thumbnail-each-time/ Share on other sites More sharing options...
Prismatic Posted January 30, 2009 Share Posted January 30, 2009 you could select the maximum largest whole square from the image, crop, then resize down to 75x75 http://www.findmotive.com/2006/08/29/create-square-image-thumbnails-with-php/ <?php function createThumb($source,$dest) { $thumb_size = 75; $size = getimagesize($source); $width = $size[0]; $height = $size[1]; if($width> $height) { $x = ceil(($width - $height) / 2 ); $width = $height; } elseif($height> $width) { $y = ceil(($height - $width) / 2); $height = $width; } $new_im = ImageCreatetruecolor($thumb_size,$thumb_size); $im = imagecreatefromjpeg($source); imagecopyresampled($new_im,$im,0,0,$x,$y,$thumb_size,$thumb_size,$width,$height); imagejpeg($new_im,$dest,100); } ?> Link to comment https://forums.phpfreaks.com/topic/143189-creating-the-perfect-thumbnail-each-time/#findComment-750998 Share on other sites More sharing options...
acctman Posted January 31, 2009 Author Share Posted January 31, 2009 thanks... this will work perfect. Link to comment https://forums.phpfreaks.com/topic/143189-creating-the-perfect-thumbnail-each-time/#findComment-751038 Share on other sites More sharing options...
acctman Posted February 2, 2009 Author Share Posted February 2, 2009 you could select the maximum largest whole square from the image, crop, then resize down to 75x75 http://www.findmotive.com/2006/08/29/create-square-image-thumbnails-with-php/ do you have an example on how to use this code? cause i've tried setting the source and dest <?php $source = "1007493051.jpg"; $dest = "test111.jpg"; function createThumb($source,$dest) { $thumb_size = 75; $size = getimagesize($source); $width = $size[0]; $height = $size[1]; if($width> $height) { $x = ceil(($width - $height) / 2 ); $width = $height; } elseif($height> $width) { $y = ceil(($height - $width) / 2); $height = $width; } $new_im = ImageCreatetruecolor($thumb_size,$thumb_size); $im = imagecreatefromjpeg($source); imagecopyresampled($new_im,$im,0,0,$x,$y,$thumb_size,$thumb_size,$width,$height); imagejpeg($new_im,$dest,100); } ?> Link to comment https://forums.phpfreaks.com/topic/143189-creating-the-perfect-thumbnail-each-time/#findComment-752545 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.