Hi guys,
this script creates BAD quality(color loss) thumb images, even though the quality is SET 100, what could be the problem?
function createThumb($f) {
// use max width config value
global $maxw, $maxh, $curdir, $thumbdir, $slash;
$type = getSuffix($f);
// png or jpeg?
// either way get image
if ($type==".png") {
$input = imagecreatefrompng($f);
} else {
$input = imagecreatefromjpeg($f);
}
if ( !$input ) {
error("not a valid image file :(");
return false;
}
// get size ( [0]=width, [1]=height )
$tmp = getimagesize($f);
if ( !$tmp ) {
error("Could not get input image size");
return false;
}
// get width of new thumbnail by taking
// the smaller value from max and tmp width
$w = ($tmp[0]>$maxw) ? $maxw : $tmp[0];
// scale height according to width
$h = $tmp[1] * ($maxw/$tmp[0]);
if ( $h>$maxh ) {
$h = $maxh;
$w = $tmp[0] * ($maxh/$tmp[1]);
}
// create output image
@ $output = imagecreate($w,$h);
if ( !$output ) {
error("could not create output image");
return false;
}
// copy big image over to thumbnail, and resize down
imagecopyresized( $output,$input, 0,0, 0,0, $w,$h, $tmp[0],$tmp[1]);
$newfile = $thumbdir.$slash.$f;
// do the outputting!
if ( $type == ".png" ) {
imagepng($output,$newfile,100); //set the quality
} else {
imagejpeg($output,$newfile,100);
}
}