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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.