how to increase 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
lukelee
Forum Commoner
Posts: 28
Joined: Wed Sep 10, 2008 2:03 am

how to increase thumbnail quality

Post by lukelee »

~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.


here is my code, the quality of the thumbnail is really bad. almost white and black with blur. anyone know how to make my code better?

Code: Select all

 
function makethumb($srcFile,$dstFile,$dstW,$dstH) {
$data = GetImageSize($srcFile,&$info);
switch ($data[2]) {
case 1:
$im = @ImageCreateFromGIF($srcFile);
break;
case 2:
$im = @imagecreatefromjpeg($srcFile);
break;
case 3:
$im = @ImageCreateFromPNG($srcFile);
break;
}
$srcW=ImageSX($im);
$srcH=ImageSY($im);
$ni=ImageCreate($dstW,$dstH);
 
Imagecopyresampled($ni,$im,0,0,0,0,$dstW,$dstH,$srcW,$srcH);
ImageJpeg($ni,$dstFile, 80);

~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.
SteveC
Forum Commoner
Posts: 44
Joined: Thu Dec 04, 2008 2:39 pm
Location: Lansing, MI

Re: how to increase thumbnail quality

Post by SteveC »

Try using imagecreatetruecolor() instead. :)
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: how to increase thumbnail quality

Post by pickle »

Increasing the 3rd argument to imagejpeg to 100 from 80 will also increase the quality of the final image file, though probably not perceivably so.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
FunkyDude
Forum Newbie
Posts: 8
Joined: Mon Dec 15, 2008 5:19 pm

Re: how to increase thumbnail quality

Post by FunkyDude »

I'm pretty sure that the image quality is negligible with GD library, I'm not entirely sure but I think using ImageMajick to create jpegs can possibly make higher quality images.
Post Reply