note 48738 added to function.imagecreate
| From: | php-general at lists dot php dot net | Date: | Wed, 05 Jan 2005 21:30:37 +0000 |
| Subject: | note 48738 added to function.imagecreate | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-82799@lists.php.net to get a copy of this message | ||
This is how you can create a thumbnail with maximum height and width. This way it will fit nicely in
a gallery table. In this example $im is the source image
<?
//calculate thumb size
$ow = imagesx($im);
$oh = imagesy($im);
$maxh = 100;
$maxw = 150;
$new_h = $oh;
$new_w = $ow;
if($oh > $maxh || $ow > $maxw){
$new_h = ($oh > $ow) ? $maxh : $oh*($maxw/$ow);
$new_w = $new_h/$oh*$ow;
}
//create dst image
$dst_img = ImageCreateTrueColor($new_w,$new_h);
//resize and copy image
ImageCopyResized($dst_img, $im, 0,0,0,0, $new_w, $new_h, ImageSX($im), ImageSY($im));
$function_image_new($dst_img,$galdir.$file);
?>
----
Manual Page -- http://www.php.net/manual/en/function.imagecreate.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+48738
Delete -- http://master.php.net/manage/user-notes.php?action=delete+48738&report=yes
Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+48738&report=yes&reason=bad+code
Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+48738&report=yes&reason=spam
Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+48738&report=yes&reason=useless+example
Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+48738&report=yes&reason=contains+commercial+links
Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+48738&report=yes&reason=useless+note
Reject -- http://master.php.net/manage/user-notes.php?action=reject+48738&report=yes
Search -- http://master.php.net/manage/user-notes.php