note 33750 deleted from ref.image by tularis

From: Date: Sun, 29 Jun 2008 21:12:03 +0000
Subject: note 33750 deleted from ref.image by tularis
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-140977@lists.php.net to get a copy of this message
Note Submitter: office at 4point-webdesign dot com ---- 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; }

« previous php.notes (#140977) next »