GD Thumbnail Quality

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
robjime
Forum Commoner
Posts: 46
Joined: Sat Apr 03, 2004 12:26 pm
Location: the RO

GD Thumbnail Quality

Post 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
User avatar
Todd_Z
Forum Regular
Posts: 708
Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan

Post 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);
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

Code: Select all

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

Code: Select all

$img_dst=imagecreatetruecolor($g_iw,$g_ih);
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
robjime
Forum Commoner
Posts: 46
Joined: Sat Apr 03, 2004 12:26 pm
Location: the RO

Post by robjime »

wow thanks man, that did the trick
User avatar
Todd_Z
Forum Regular
Posts: 708
Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan

Post by Todd_Z »

just curious - which post are you refering to?
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

Todd_Z wrote:just curious - which post are you refering to?
Heh, me also.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Post Reply