Jump to content


Photo

Thumbnail losing color *solved*


  • Please log in to reply
2 replies to this topic

#1 Tsukiyomi

Tsukiyomi
  • Members
  • PipPip
  • Member
  • 29 posts

Posted 17 October 2006 - 07:10 PM

I've been using the following script to create thumbnails

$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);

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:

Posted Image

New:

Posted Image

Thanks.

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 17 October 2006 - 07:24 PM

Create $dst image using imagecreatetruecolor()
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 Tsukiyomi

Tsukiyomi
  • Members
  • PipPip
  • Member
  • 29 posts

Posted 17 October 2006 - 08:10 PM

Thank you very much.  Works perfectly.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users