note 15830 rejected from function.imagecopyresized by sander
| From: | sander@php.net | Date: | Sat, 06 Apr 2002 19:21:06 +0000 |
| Subject: | note 15830 rejected from function.imagecopyresized by sander | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-28772@lists.php.net to get a copy of this message | ||
The following PHP will take an jpeg filename + size and will return a resized jpeg.
// variables from URL
// id=imagefilename (without.jpg)
// sz=maxsize
$im = imagecreatefromjpeg("/path/to/your/jpegs/$id.jpg");
$im_width=imageSX($im);
$im_height=imageSY($im);
// work out new sizes
if($im_width >= $im_height)
{
$factor = $sz/$im_width;
$new_width = $sz;
$new_height = $im_height * $factor;
}
else
{
$factor = $sz/$im_height;
$new_height = $sz;
$new_width = $im_width * $factor;
}
// resize
$new_im=ImageCreate($new_width,$new_height);
ImageCopyResized($new_im,$im,0,0,0,0,$new_width,$new_height,$im_width,$im_height);
// output
header("Content-type: image/jpeg");
Imagejpeg($new_im,'',75); // quality 75
// cleanup
ImageDestroy($im);
ImageDestroy($new_im);