Forum Moderators: coopster

Message Too Old, No Replies

Image Resizing Quality

         

ryan_b83

2:05 am on Nov 4, 2006 (gmt 0)

10+ Year Member



Hello, I am currently using the following function to resize and move a validated image. However i notice that the quality of the image after being resized is not 100% as good as it would be if i did it in fireworks or photoshop. Is there a better method to maintin high quality images? Or is this a limitation of php?

Thanks,
Ryan

function resize_move_image($file, $upfile, $max_width, $max_height){

$size = GetImageSize($file);
$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;
}

$quality = 100;

$destimg=imagecreatetruecolor($tn_width,$tn_height) or die("Problem In Creating image");

$srcimg=imagecreatefromjpeg($file) or die("Problem In opening Source Image");

imagecopyresized($destimg,$srcimg,0,0,0,0,$tn_width,$tn_height,ImageSX($srcimg),ImageSY($srcimg)) or die("Problem In resizing");

imagejpeg($destimg,$upfile,$quality) or die("Problem In saving");

}

FalseDawn

6:01 pm on Nov 4, 2006 (gmt 0)

10+ Year Member



Use imagecopyresampled instead of imagecopyresized
[us3.php.net...]

ryan_b83

7:18 pm on Nov 5, 2006 (gmt 0)

10+ Year Member



Works Great!

Thanks!