固定大小的缩略图,如twitpic.com

How do you create a fixed size (height / width) of images/thumbnails In GD?

I know there is a lot of php scripts out there but that just scale it and height/width will always be different size.

I like the thumbnail like twitpic.com and facebook

You need to get the height and width of the image using getimagesize

and then resize it using imagecopyresized

The rest is all the same basic work done with GD to load and save the image.

Here's a basic example, if you want to take into account height/width ratios, then you have to do some additional maths.

<?php
header("Content-type: image/png");

$size = getimagesize($filename);
$image     = imagecreatefrompng($filename);
$thumbnail = imagecreate(100,100);
imagecopyresized($thumbnail, $image, 0, 0, 0, 0, 100, 100, $size[0], $size[1]);
imagepng($thumbnail);
imagedestroy($image);
imagedestroy($thumbnail);

It's easy with Thumbnailer:

$th=new Thumbnailer("your-photo.jpg");
$th->thumbSquare(100)->save("thumb.jpg");