Jump to content

creating the perfect thumbnail each time?


acctman

Recommended Posts

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

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);
}
?>

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);

} 

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.