I am making thumbnails out of .jpg files, and some of them are of really poor quality. Some may come out in black and white. Some may be milky. Some may be blurry. Some may look like negatives (i.e., very dark). Many look just fine. I have checked the full-size photos of many of the poor-quality thumbnails, and the full-size photos appear fine.
Does anyone know of a way to address this problem?
Here is the code I am using:
function createthumb($name,$filename,$new_w){
// These lines get the information if gd is at least version 2.0 and check if the original image is a JPEG or PNG
// and a new image object is created called src_image
global $gd2;
$system=explode(".",$name);
if (preg_match("/jpg|jpeg/",$system[1])){
$src_img = @imagecreatefromjpeg($name); / Attempt to open /
if (!$src_img) { / See if it failed /
}
}
// These lines get the dimensions of the original image by using imageSX() and imageSY(),
// and calculate the dimensions of the thumbnail accordingly, keeping the correct aspect ratio.
// The desired dimensions are stored in thumb_w and thumb_h.
$old_x=imageSX($src_img);
$old_y=imageSY($src_img);
$thumb_w=$new_w;
$thumb_h=$old_y/$old_x * $new_w;
//These lines check the version of gd (coming from checkgd()) and create the image either as a 256 colour version using ImageCreate()
// or as a true colour version using ImageCreateTrueColor().
if ($gd2==""){
$dst_img=ImageCreate($thumb_w,$thumb_h);
imagecopyresized($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);
}else{
$dst_img=ImageCreateTrueColor($thumb_w,$thumb_h);
imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);
}
// Then the original image gets resized, respectively resampled and copied into the new thumbnail image, on the top left position
if (preg_match("/png/",$system[1])){
imagepng($dst_img,$filename);
} else {
imagejpeg($dst_img,$filename);
}
imagedestroy($dst_img);
imagedestroy($src_img);
}
Thank you for any assistance you may provide!
Mel