This works like a charm on JPG, haven't tried it on other files types. This
came from the www.php.net
function image_createThumb($src,$dest,$maxWidth,$maxHeight,$quality=100) {
if (file_exists($src) && isset($dest)) {
// path info
$destInfo = pathInfo($dest);
// image src size
$srcSize = getImageSize($src);
// image dest size $destSize[0] = width, $destSize[1] = height
$srcRatio = $srcSize[0]/$srcSize[1]; // width/height ratio
$destRatio = $maxWidth/$maxHeight;
if ($destRatio > $srcRatio) {
$destSize[1] = $maxHeight;
$destSize[0] = $maxHeight*$srcRatio;
}
else {
$destSize[0] = $maxWidth;
$destSize[1] = $maxWidth/$srcRatio;
}
// path rectification
if ($destInfo['extension'] == "gif") {
$dest = substr_replace($dest, 'jpg', -3);
}
// true color image, with anti-aliasing
$destImage = imageCreateTrueColor($destSize[0],$destSize[1]);
//CAE imageAntiAlias($destImage,true);
// src image
switch ($srcSize[2]) {
case 1: //GIF
$srcImage = imageCreateFromGif($src);
break;
case 2: //JPEG
$srcImage = imageCreateFromJpeg($src);
break;
case 3: //PNG
$srcImage = imageCreateFromPng($src);
break;
default:
return false;
break;
}
// resampling
imageCopyResampled($destImage, $srcImage, 0, 0, 0,
0,$destSize[0],$destSize[1],$srcSize[0],$srcSize[1]);
// generating image
switch ($srcSize[2]) {
case 1:
case 2:
imageJpeg($destImage,$dest,$quality);
break;
case 3:
imagePng($destImage,$dest);
break;
}
return true;
}
else {
return false;
}
}
//// Calling code
if ($photosize >= 102400 ) {
$blReduce = true;
}
// reduce the size of a file down to 720x720 pixels at 80% quality
if ($blReduce) {
image_createThumb($src,$src,720,720,80);
}
//Create a thumbnail were the maximum width or height is 100 pixels at
100% quality
// $src is the full path/filename of the large jpg file
//$desc is the full path/filename of the thumbnail to be created
image_createThumb($src,$dest,100,100,100);
----- Original Message -----
From: "Matt Matijevich" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
Sent: Tuesday, January 20, 2004 6:24 PM
Subject: Re: [PHP] thumbnail
> [snip]
> OK, but how? I already use GD, I need to now how to create a thumbnail,
>
> somebody now how to use the GD functions to create a thumbnail???
> [/snip]
>
> http://www.php.net/GD
>
> I think you want to look at:
> imagecopyresampled -- Copy and resize part of an image with resampling
> imagecopyresized -- Copy and resize part of an image
>
> or try this pear class http://pear.php.net/package/Image_Transform
> like <[EMAIL PROTECTED]> suggested.
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php