ColdEdge Posted November 24, 2009 Share Posted November 24, 2009 Hello I have this script to generate thumbnails and upload image to separate folder. However when the thumb is made/shown it looks bad in quality. How can I improve the quality of the thumb thats being generated?Here is an example of what the thumbnail quality is like: but I want it to be shown same as its original image in high quality not pixelated. And here is a thumbnail from a different site you can see there is a major difference in pic quality.Here is the code <?phpfunction createThumbnail($filename) { require 'config.php'; if(preg_match('/[.](jpg)$/', $filename)) { $im = imagecreatefromjpeg($path_to_image_directory . $filename); } else if (preg_match('/[.](gif)$/', $filename)) { $im = imagecreatefromgif($path_to_image_directory . $filename); } else if (preg_match('/[.](png)$/', $filename)) { $im = imagecreatefrompng($path_to_image_directory . $filename); } $ox = imagesx($im); $oy = imagesy($im); $nx = $final_width_of_image; $ny = floor($oy * ($final_width_of_image / $ox)); $nm = imagecreatetruecolor($nx, $ny); imagecopyresized($nm, $im, 0,0,0,0,$nx,$ny,$ox,$oy); if(!file_exists($path_to_thumbs_directory)) { if(!mkdir($path_to_thumbs_directory)) { die("There was a problem. Please try again!"); } } imagejpeg($nm, $path_to_thumbs_directory . "thumb-" . $filename); $tn = '<img src="' . $path_to_thumbs_directory . "thumb-" . $filename . '" alt="image" style="width:150px;height:112px;border:2px solid #000;padding:4px;"/>'; $tn .= '<br />Congratulations. Your file has been successfully uploaded, and a thumbnail has been created.'; echo $tn; } ?> The config file is just this.... $final_width_of_image = 150; $path_to_image_directory = 'images/fullsize/'; $path_to_thumbs_directory = 'images/thumbs/'; Link to comment Share on other sites More sharing options...
thescientist Posted November 24, 2009 Share Posted November 24, 2009 Whats the aspect ratio of the uploaded picture to the thumbnail? Depending on the size of the uploaded picture, and the ratio of the thumbnail to the picture, maybe that's why its looking pixelated? Link to comment Share on other sites More sharing options...
ColdEdge Posted November 24, 2009 Author Share Posted November 24, 2009 The images can be as massive as 1600 x 1200 px but all I want is the thumbnail to be 150 x 112 px in good quality. Link to comment Share on other sites More sharing options...
justsomeguy Posted November 24, 2009 Share Posted November 24, 2009 Use imagecopyresampled instead of imagecopyresized. Link to comment Share on other sites More sharing options...
ColdEdge Posted November 24, 2009 Author Share Posted November 24, 2009 the quality went up. Thank you. But still my preview with updated quality is not close to the other thumbnail I posted from other site. What is causing this lack of quality? They both are made as .jpg Link to comment Share on other sites More sharing options...
ColdEdge Posted November 24, 2009 Author Share Posted November 24, 2009 Here is a preview from other site and here is the very same image converted by the script I am using. As you can see my quality is still lacking a bit. Is there a way to increase it? To say high JPG quality. Link to comment Share on other sites More sharing options...
justsomeguy Posted November 24, 2009 Share Posted November 24, 2009 You can set the JPEG compression level when you use imagejpeg to save it.http://www.php.net/manual/en/function.imagejpeg.php Link to comment Share on other sites More sharing options...
ColdEdge Posted November 24, 2009 Author Share Posted November 24, 2009 thanks for the support ^^ now all I have to do is edit the code a bit more from what I already have pre made so that PHP can generate a random 6 character random string like 7kl86i9.jpg, .png, .gif, .jpeg and allow this value to be passed to MySQL database along side with thumbnail to be stores as a record in MySQL tables. Link to comment Share on other sites More sharing options...
jlhaslip Posted November 25, 2009 Share Posted November 25, 2009 I have some random-generator script written if you need it.http://www.jlhaslip.trap17.com/shuffle/index.phpsend me a pm if you want the source code. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.