Jump to content

Thumbnail losing color *solved*


Tsukiyomi

Recommended Posts

I've been using the following script to create thumbnails

[code]
$image = "$d/images/avatar.jpg";
$start_image = "avatar.jpg";
$savelocation = "$d/images/";
if(!file_exists("$path_to_images")) {
$oldumask = umask(0);
mkdir("$path_to_thumbnail_dir", 0777);
umask($oldumask);
}
if (!$max_width) $max_width = 125;
if (!$max_height) $max_height = 125;
$size = GetImageSize($image);
$width = $size[0];
$height = $size[1];
$x_ratio = $max_width / $width;
$y_ratio = $max_height / $height;
if (($width <= $max_width) && ($height <= $max_height)) {
$tn_width = $width;
$tn_height = $height;
} else if (($x_ratio * $height) < $max_height) {
  $tn_height = ceil($x_ratio * $height);
  $tn_width = $max_width;
} else {
  $tn_width = ceil($y_ratio * $width);
  $tn_height = $max_height;
}
$src = ImageCreateFromJpeg($image);
$dst = ImageCreate($tn_width,$tn_height);
ImageCopyResized($dst, $src, 0, 0, 0, 0, $tn_width,$tn_height,$width,$height);
ImageJpeg($dst,"$savelocation"."thumb_$start_image");
//the above line is what creates the actual thumbnail jpeg
ImageDestroy($src);
ImageDestroy($dst);[/code]

It works fine, the image is created at the proper size with the aspect ratio preserved, the only problem is I'm losing a lot of color quality.  Can someone please explain to me why this is?

Here are the two images:

Original:

[img]http://img.photobucket.com/albums/v143/GammaBeast/avatar.jpg[/img]

New:

[img]http://img.photobucket.com/albums/v143/GammaBeast/thumb_avatar.jpg[/img]

Thanks.
Link to comment
https://forums.phpfreaks.com/topic/24250-thumbnail-losing-color-solved/
Share on other sites

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.