Tsukiyomi Posted October 17, 2006 Share Posted October 17, 2006 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 jpegImageDestroy($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. Quote Link to comment Share on other sites More sharing options...
Barand Posted October 17, 2006 Share Posted October 17, 2006 Create $dst image using imagecreatetruecolor() Quote Link to comment Share on other sites More sharing options...
Tsukiyomi Posted October 17, 2006 Author Share Posted October 17, 2006 Thank you very much. Works perfectly. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.