Jump to content

Gd Library Question


ColdEdge

Recommended Posts

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: thumb-1600-by-1200-159500-20081216224723.jpg 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 thumb-100140-20091123023947.jpg 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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...