所以我有以下脚本来调整传入的jpg的大小并以新的大小将其保存到服务器。创建的jpg文件质量很差,即使我在imagejpeg上制作了90的质量。我想知道我是否在早些时候搞砸了。
// Get new sizes
list($width, $height) = getimagesize($filename);
$percentW=298/$width;
$newwidth = $width * $percentW;
$newheight = $height * $percentW;
// Creating a blank canvas to put the new file. Is this an extra step?
$thumb = imagecreatetruecolor($newwidth, $newheight);
$source = imagecreatefromjpeg($filename);
// Now I create the resized photo with the needed width and height on the blank canvas with the source file resized
imagecopyresampled($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
// Output to server, define 90% quality. My guess is the quality is destroyed before now.
imagejpeg($thumb,"../../uploads/buckets/" . $_POST["bucket"] . "/" .$fileNameBucket,90);
imagedestroy($thumb);
在将文件输出到服务器之前,我是否搞砸了质量?我应该使用resample而不是resize吗?我很难使用GD库,所以ImageMagick不是一个选项。感谢。