note 33750 added to ref.image
| From: | office at 4point-webdesign dot com | Date: | Sun, 06 Jul 2003 19:29:15 +0000 |
| Subject: | note 33750 added to ref.image | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-51590@lists.php.net to get a copy of this message | ||
Here's a funtion i used to resize and save images uploaded by the user, you can either create
thumbnails or other images.
Main "feature" is that the width and height stay relativ to each other.
imgcomp is the quality, i turned it around so now its from 0 -best to 100 -most compressed.
For gif version just change the functions names.
function resampimagejpg($forcedwidth, $forcedheight, $sourcefile, $destfile, $imgcomp)
{
$g_imgcomp=100-$imgcomp;
$g_srcfile=$sourcefile;
$g_dstfile=$destfile;
$g_fw=$forcedwidth;
$g_fh=$forcedheight;
if(file_exists($g_srcfile))
{
$g_is=getimagesize($g_srcfile);
if(($g_is[0]-$g_fw)>=($g_is[1]-$g_fh))
{
$g_iw=$g_fw;
$g_ih=($g_fw/$g_is[0])*$g_is[1];
}
else
{
$g_ih=$g_fh;
$g_iw=($g_ih/$g_is[1])*$g_is[0];
}
$img_src=imagecreatefromjpeg($g_srcfile);
$img_dst=imagecreate($g_iw,$g_ih);
imagecopyresampled($img_dst, $img_src, 0, 0, 0, 0, $g_iw, $g_ih, $g_is[0], $g_is[1]);
imagejpeg($img_dst, $g_dstfile, $g_imgcomp);
imagedestroy($img_dst);
return true;
}
else
return false;
}
----
Manual Page -- http://www.php.net/manual/en/ref.image.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+33750
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+33750&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+33750&report=yes