views:

109

answers:

3

hi, im looking to create thumbnails that has 100px by 100px dimension. i've seen many articles explaining the methods but most end up having the width!=height if the dimension ratio is to be kept.

for example, i have a 450px by 350px image. i would like to crop to 100px by 100px. if i were to keep the ratio, i would end up having 100px by 77px. this makes it ugly when im listing these images in a row and column. however, a image without dimension ratio will look terrible as well.

i've seen images from flickr and they look fantastic. for example:
thumbnail: http://farm1.static.flickr.com/23/32608803_29470dfeeb_s.jpg
medium size: http://farm1.static.flickr.com/23/32608803_29470dfeeb.jpg
large size: http://farm1.static.flickr.com/23/32608803_29470dfeeb_b.jpg

tks

+1  A: 

This is fairly simple with ImageMagick and PHP. Have a look at Different aspects of thumbnailing, and Again some examples..cropThumbnailImage() on Mikko's Blog.

Mike
hey mike, i've taken a look at imagemagick. it also mention about imagick which can be found here http://www.imagemagick.org/script/api.php. under PHP, there are MagickWand, IMagick and phMagick. im a little confuse, what should i download/install?
I use [IMagick](http://uk3.php.net/manual/en/imagick.setup.php)
Mike
hey mike, im having trouble installing imagick with xampp 1.73, php 5.3.1.im using imagick from http://valokuva.org/outside-blog-content/imagick-windows-builds/php53/imagick-2.3.0-dev/vc9_zts/i've upgrade my php to vc9 x86 thread safe but still not working. it keep prompting :unable to load dynamic library D:/.../php_imagick.dll
hey mike, looks like im going with Sven Koschnicke. but tks ur idea is great too. =)
+1  A: 

This is done by only using a part of the image as the thumbnail which has a 1:1 aspect ratio (mostly the center of the image). If you look closely you can see it in the flickr thumbnail.

Because you have "crop" in your question, I'm not sure if you didn't already know this, but what do you want to know then?

To use cropping, here is an example:

//Your Image
$imgSrc = "image.jpg";

//getting the image dimensions
list($width, $height) = getimagesize($imgSrc);

//saving the image into memory (for manipulation with GD Library)
$myImage = imagecreatefromjpeg($imgSrc);

// calculating the part of the image to use for thumbnail
if ($width > $height) {
  $y = 0;
  $x = ($width - $height) / 2;
  $smallestSide = $height;
} else {
  $x = 0;
  $y = ($height - $width) / 2;
  $smallestSide = $width;
}

// copying the part into thumbnail
$thumbSize = 100;
$thumb = imagecreatetruecolor($thumbSize, $thumbSize);
imagecopyresampled($thumb, $myImage, 0, 0, $x, $y, $thumbSize, $thumbSize, $smallestSide, $smallestSide);

//final output
header('Content-type: image/jpeg');
imagejpeg($thumb);
Sven Koschnicke
Hi skoschnike *double check if i spelled ur name correctly =)*that has cross my mind. but im clueless on how to do that. care to share??
hey sven, i tried ur script and it works great. tk you so much. flawless
hey sven, i just have a question. using ur script works great. but i realised the quality of image after cropping is not the same as the original. for instance, i took a sample pic from flickr and crop to the same dimension and they look different. any solution to retain the quality??
you can specify the jpg-quality in the imagejpeg() function, see here http://de.php.net/imagejpeg (use NULL for the filename parameter). The default quality is 75.
Sven Koschnicke
tks sven, i overlook the property. now it works!!
A: 

I like using GDLib to fiddle with images, it's fantastically easy to work with also. There are lots of blog posts and tutorials out there. I would recommend using a class for it or similar though, as taking care of all the variations in the image can be very time consuming.

DavidYell
Have a go with this perhaps? http://pear.php.net/package/Image_Transform
DavidYell