0

所以我有以下脚本来调整传入 jpg 的大小并将其以新大小保存到服务器。即使我在 imagejpeg 上制作质量 90,创建的 jpg 文件质量也很差。我想知道我是否在我的努力中把它搞砸了。

// 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);

我什至在将文件输出到服务器之前就搞砸了质量吗?我应该使用重新采样而不是调整大小吗?我坚持使用 GD 库,所以 ImageMagick 不是一个选项。谢谢。

4

0 回答 0