PDA

View Full Version : thumb nail problem


xiaodao
01-19-2006, 03:03 AM
hi, i am developing a script that user can upload picture, the picture may be rectange or square, but i want to create thumb nail for them a fixed size like 25*25
for square picture it is ok, but for rectangle picture i want them to crop 20*25 from the original picture to as thumb
How to do?

ralph l mayo
01-19-2006, 03:18 AM
marginally tested solution:

$dims = getimagesize('ewww1.jpg');
$newdims = $dims[0] > $dims[1] ? array('width'=>25, 'height'=>(int)($dims[1] / ($dims[0] / 25))) : array('width'=>(int)($dims[0] / ($dims[1] / 25)), 'height'=>25);


$newdims will be an array with the keys 'width' and 'height'. If you're using some other method to get dimensions besides getimagesize(), replace $dims[0] with width and $dims[1] with height (or vice versa, so long as they're different :)

xiaodao
01-19-2006, 03:43 AM
............what to do next?

ralph l mayo
01-19-2006, 03:54 AM
Oh, I thought you had the 25x25 part working.

see: imagecopyresampled() (http://us2.php.net/imagecopyresampled)