dsartain Posted February 15, 2007 Share Posted February 15, 2007 I've got a function that I'm using to make thumbnails out of images....but the problem is that it's fading the images....I can't figure out why though....please help!! // actual function function thumbnail($image_path,$thumb_path,$image_name,$thumb_width) { $src_img = imagecreatefromjpeg("$image_path/$image_name"); $origw=imagesx($src_img); $origh=imagesy($src_img); $new_w = $thumb_width; $new_h=($origh*($new_w))/$origw; //added to get better proportions $diff=$origw/$new_w; //$new_h=$new_w; //removed to get better proportions $dst_img = imagecreate($new_w,$new_h); imagecopyresized($dst_img,$src_img,0,0,0,0,$new_w,$new_h,imagesx($src_img),imagesy($src_img)); imagejpeg($dst_img, "$thumb_path/$image_name"); return true; } //usage thumbnail("/var/www/html/dsartain/images/gallery/", "/var/www/html/dsartain/images/gallery/thumbnails/", $userfile_l_name, 150) ; Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 15, 2007 Share Posted February 15, 2007 That sounds odd. Can you show us an example image? Does it happen with gif or png too? Quote Link to comment Share on other sites More sharing options...
dsartain Posted February 15, 2007 Author Share Posted February 15, 2007 Go to http://www.the24hourshow.net/dsartain/gallery.php The two images with "Blue Wall" Captions and the one with "Swimming Lessons"...all are towards the bottom...images as colors should appear are on that page also (though I didn't use GD2 for those...) Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 15, 2007 Share Posted February 15, 2007 It looks like it's the quality being reduced. Use this instead http://us3.php.net/manual/en/function.imagecopyresampled.php Quote Link to comment Share on other sites More sharing options...
dsartain Posted February 15, 2007 Author Share Posted February 15, 2007 One other thing...the actual mime type is "image/pjpeg"...I don't know if that makes a difference...and this fuction won't handle .gif or .png...though it would be amazing if I could get it to do that... Quote Link to comment Share on other sites More sharing options...
dsartain Posted February 15, 2007 Author Share Posted February 15, 2007 Nope, same thing happened....see above link... Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 15, 2007 Share Posted February 15, 2007 It's very easy to resize any type of images - there are lots of already made scripts and tutorials out there. Quote Link to comment Share on other sites More sharing options...
dsartain Posted February 15, 2007 Author Share Posted February 15, 2007 well, this seems to work as far as the resizing goes when it comes to the JPEG format...but worthless if the image quality keeps being reduced...any other ideas?? Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 15, 2007 Share Posted February 15, 2007 if you're using resampled and not resized, it shouldn't do that. Can you post your new code? Quote Link to comment Share on other sites More sharing options...
dsartain Posted February 15, 2007 Author Share Posted February 15, 2007 function thumbnail($image_path,$thumb_path,$image_name,$thumb_width) { $src_img = imagecreatefromjpeg("$image_path/$image_name"); $origw=imagesx($src_img); $origh=imagesy($src_img); $new_w = $thumb_width; $new_h=($origh*($new_w))/$origw; //added to get better proportions $diff=$origw/$new_w; //$new_h=$new_w; //removed to get better proportions $dst_img = imagecreate($new_w,$new_h); imagecopyresampled($dst_img,$src_img,0,0,0,0,$new_w,$new_h,imagesx($src_img),imagesy($src_img)); //just added 100 for $quality...no change in display though imagejpeg($dst_img, "$thumb_path/$image_name", 100); return true; } Quote Link to comment Share on other sites More sharing options...
dsartain Posted February 15, 2007 Author Share Posted February 15, 2007 whoops!!! I forgot one minor thing.... function thumbnail($image_path,$thumb_path,$image_name,$thumb_width) { $src_img = imagecreatefromjpeg("$image_path/$image_name"); $origw=imagesx($src_img); $origh=imagesy($src_img); $new_w = $thumb_width; $new_h=($origh*($new_w))/$origw; //added to get better proportions $diff=$origw/$new_w; $dst_img = imagecreatetruecolor($new_w,$new_h); //I left this line out...doh!! imagecopyresampled($dst_img,$src_img,0,0,0,0,$new_w,$new_h,imagesx($src_img),imagesy($src_img)); imagejpeg($dst_img, "$thumb_path/$image_name", 100); return true; } Thanks a lot for the help!!! Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 15, 2007 Share Posted February 15, 2007 Heh, glad you got it 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.