nevynev Posted August 30, 2007 Share Posted August 30, 2007 Hi there, If I have an image which has a height/witdth smaller than the standard $forcedwitdht and $forcedheight and use the function below it resizes them to fit that size but I want it to remain the original size. For clarity. if $forcedheight is 400 and $forcedwidth is 500 If I use this function on a 50 x 70 image I DONT want it to be resized to 400x500. Obvisouly at the moment the script is aimed at larger images (e.g. 1024 x 768). The function is: <?php 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=imagecreatetruecolor($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; } ?> I guess it would be a simple if (height and width is less than){}else{} sort of thing but I can't seem to make it work. Thanks for any help NevyNev Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted August 30, 2007 Share Posted August 30, 2007 you have answered your own question. You need to check the size of the image - if its less than the forced width/height then don't resize it. Quote Link to comment Share on other sites More sharing options...
nevynev Posted August 30, 2007 Author Share Posted August 30, 2007 Yes but how do I do that within this function (I didnt write it!) Thanks NevyNev Quote Link to comment Share on other sites More sharing options...
Jessica Posted August 30, 2007 Share Posted August 30, 2007 You don't - just don't resize them if they are too small. Use getimagesize() to figure it out. Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted August 31, 2007 Share Posted August 31, 2007 thanks jessie - I clearly wasn't being clear! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.