Page 1 of 1

GD Thumbnail Quality

Posted: Wed Aug 10, 2005 3:14 pm
by robjime
I have this function which creates thumbnails for jpegs but the quality is bad. Any one know why?

Code: Select all

function thumbjpg($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);
       imagedestroy($img_dst);
       return true;
       }
       else
       return false;
	   
   }
for image comp, i but in 0, which is the best quality and 100, which is the worst quality
thanks

Posted: Wed Aug 10, 2005 4:02 pm
by Todd_Z
I may be blind, but you don't specify the quality of the jpg anywhere.

I dont see $g_imgcomp used after you set it to 100-$imgcomp;

ignore those vars and use

Code: Select all

imagejpeg($img_dst, $g_dstfile, 100);

Posted: Wed Aug 10, 2005 4:38 pm
by s.dot

Code: Select all

$img_dst=imagecreate($g_iw,$g_ih);
to

Code: Select all

$img_dst=imagecreatetruecolor($g_iw,$g_ih);

Posted: Wed Aug 10, 2005 9:31 pm
by robjime
wow thanks man, that did the trick

Posted: Wed Aug 10, 2005 11:11 pm
by Todd_Z
just curious - which post are you refering to?

Posted: Wed Aug 10, 2005 11:35 pm
by s.dot
Todd_Z wrote:just curious - which post are you refering to?
Heh, me also.