旋转图像会降低质量


Rotate image reduce quality

我有一个用户可以左右旋转图像的页面。

问题是,当用户旋转图像4-5次时,质量会大大降低!

我做错了吗?

        $image_source = imagecreatefromjpeg($path_u);
        $rotate = imagerotate($image_source, $angle, 0);
        imageinterlace($rotate, true); //this is to create progressive jpeg
        imagejpeg($rotate, $path_u, 100);
        imagedestroy($rotate);

反复修改和重新压缩图像(特别是在JPEG中,无论质量设置如何,它都是有损的)最终必然会导致乘法伪影。您最好保留原始图像,并且当请求旋转时,重新旋转原始图像,而不是每次都保存原始图像。

如果我说错了请纠正我,但是在2014年,我们现在可以旋转jpeg图片,不是没有质量损失,而是通过认真地减少它。

Imagejpeg方法有一个"quality"参数,帮助设置所需的质量保存。

我尝试多次旋转相同的图像,并且,质量损失是不可见的人眼。

代码如下:

    header("Content-type: image/jpeg");
    $source = imagecreatefromjpeg($pictureUrl);
    $rotate = imagerotate($source, $degrees, 0);
    imagejpeg($rotate, $pictureUrl, 100);
    imagedestroy($source);
    imagedestroy($rotate);