我已经实现了这个方法(通过以下PHP教程)来创建图像的预览:
function createPreview($image_path,$filename) { header('Content-Type: image/jpeg'); $thumb = imagecreatetruecolor(350,350); $source = imagecreatefromjpeg($image_path); list($width,$height) = getimagesize($image_path); imagecopyresized($thumb,$source,350,$width,$height); imagejpeg($thumb,$filename."_prev.jpg"); }
但我注意到缩放图像损失了很多质量.我怎样才能保持缩放图像的质量(我不能使用想象力,我的服务器不支持它)
imagejpeg默认使用75质量.所以你需要明确定义它.
imagejpeg($thumb,$filename."_prev.jpg",100);
另外,使用imagecopyresampled
imagecopyresampled() copies a rectangular portion of one image to another image,smoothly interpolating pixel values so that,in particular,reducing the size of an image still retains a great deal of clarity.