note 15830 added to function.imagecopyresized
| From: | php dot net at breakingart_no_sp_am dot com | Date: | Thu, 04 Oct 2001 12:17:18 +0000 |
| Subject: | note 15830 added to function.imagecopyresized | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-18560@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);
--
http://www.php.net/manual/en/function.imagecopyresized.php
http://master.php.net/manage/user-notes.php?action=edit+15830
http://master.php.net/manage/user-notes.php?action=delete+15830
http://master.php.net/manage/user-notes.php?action=reject+15830