调整PNG大小而不会降低质量和透明度

问题描述 投票:2回答:2

我必须调整图像大小,导致我们上传可打印的高分辨率图像,并且对于预览,人们不需要4000px +图像。一些图像使用rgb颜色空间“eci”和其他使用颜色空间srgb。 srgb文件没有任何问题,但eci看起来比以前有点无色。当我上传透明图像时,它不完美透明。有什么解决方案吗?当我调整大小和它的png图像时,我使用以下额外功能。

private function imagetranstowhite($trans) {
    // Create a new true color image with the same size
    $w = imagesx($trans);
    $h = imagesy($trans);
    $white = imagecreatetruecolor($w, $h);

    // Fill the new image with white background
    $bg = imagecolorallocate($white, 255, 255, 255);
    imagefill($white, 0, 0, $bg);

    // Copy original transparent image onto the new image
    imagecopy($white, $trans, 0, 0, 0, 0, $w, $h);

    return $white;
}

有没有人有办法解决吗? Imagemagick而不是gdlib也很好。

php gdlib
2个回答
0
投票

对于将来遇到同样问题的人。我通过停止使用imagegd并切换到ImageMagick来解决它。所有图像仍然是透明的,您可以使用正确的ICC配置文件轻松地将cmyk图像转换为sRGB


-2
投票

虚拟地,不要使PNG更大。相反,从你需要的PNG分辨率开始,然后根据需要进行虚拟缩小。这样你就可以保持PNG的分辨率,并且在那之后再也不用再麻烦了。这是最快,最简单,最好的解决方案。

© www.soinside.com 2019 - 2024. All rights reserved.