|
Posted by nescio on 04/04/06 10:05
i use gd2 to make thumbnails en a smaller format of images to show on the
web.
the only problem is: a terrible loss of qualitiy
is there a way to prevent this, or is there an other possibility to make
smaller images on the fly?
----------------------------- source code ---------------------------
$image: name of the image that must become a smaller image;
$max_width: max width of the smaller image;
$max_height: max height of the smaller image;
$file_name_dest: name of the smaller image;
function maakPlaatje($image, $max_width, $max_height, $file_name_dest){
$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 = imagecreatetruecolor($tn_width,$tn_height);
ImageCopyResized($dst, $src, 0, 0, 0, 0,
$tn_width,$tn_height,$width,$height);
$quality = 100;
$fh=fopen($file_name_dest,'w');
fclose($fh);
imagejpeg($dst,$file_name_dest, $quality);
ImageDestroy($src);
ImageDestroy($dst);
return true;
}
------------------------------------------------------------------------
thanks
[Back to original message]
|