You are here: gd and loss of quality « All PHP « IT news, forums, messages
gd and loss of quality

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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация