note 61938 added to function.imagejpeg
| From: | php-general at lists dot php dot net | Date: | Wed, 15 Feb 2006 15:44:03 +0000 |
| Subject: | note 61938 added to function.imagejpeg | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-103774@lists.php.net to get a copy of this message | ||
THUMBNAIL GENERATOR
Hope someone will find this usefull... save it to thumb.php and use it for on-the-fly thumbnails
generating
e.g.
<img src=
"thumb.php?src=pic.jpg&wmax=150&hmax=100&quality=90&bgcol=FF0000">
</img>
<?php
// by dooobd@NOSPAM.doobd.com
//
// proportional on-the-fly thumb generator from JPG images
//
// usage example:
// <img src=
"thumb.php?src=pic.jpg&wmax=150&hmax=100&quality=90&bgcol=FF0000">
</img>
//
// parameters: src = source image
// wmax = max width
// hmax = max height
// quality = JPG quality of generated thumb - optional.
// if not specified, quality=90
// bgcol = if specified, allways generates exact wmax x hmax sized thumb,
// with bacground color bgcol and centered source image
//
// note: if source image is smaller than desired thumbnail, it will not be resized!
header("Content-type: image/jpeg");
$source = imagecreatefromjpeg($src);
$orig_w=imagesx($source);
$orig_h=imagesy($source);
if ($orig_w>$wmax || $orig_h>$hmax)
{
$thumb_w=$wmax;
$thumb_h=$hmax;
if ($thumb_w/$orig_w*$orig_h>$thumb_h)
$thumb_w=round($thumb_h*$orig_w/$orig_h);
else
$thumb_h=round($thumb_w*$orig_h/$orig_w);
} else
{
$thumb_w=$orig_w;
$thumb_h=$orig_h;
}
if (!@$bgcol)
{
$thumb=imagecreatetruecolor($thumb_w,$thumb_h);
imagecopyresampled($thumb,$source,
0,0,0,0,$thumb_w,$thumb_h,$orig_w,$orig_h);
}
else
{
$thumb=imagecreatetruecolor($wmax,$hmax);
imagefilledrectangle($thumb,0,0,$wmax-1,$hmax-1,intval($bgcol,16));
imagecopyresampled($thumb,$source,
round(($wmax-$thumb_w)/2),round(($hmax-$thumb_h)/2),
0,0,$thumb_w,$thumb_h,$orig_w,$orig_h);
}
if (!@$quality) $quality=90;
imagejpeg($thumb,"",$quality);
imagedestroy($thumb);
?>
----
Server IP: 161.53.30.180
Probable Submitter: 83.131.60.193
----
Manual Page -- http://www.php.net/manual/en/function.imagejpeg.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+61938
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+61938&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+61938&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+61938&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+61938&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+61938&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+61938&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+61938&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+61938&report=yes
Search -- http://master.php.net/manage/user-notes.php