【发布时间】:2014-12-06 12:19:59
【问题描述】:
我在使用 imagewebp 将图像转换为 webp 时遇到问题。
我使用这个代码:
$filename = dirname(__FILE__) .'/example.jpg';
$im = imagecreatefromjpeg($filename);
$webp =imagewebp($im, str_replace('jpg', 'webp', $filename));
imagedestroy($im);
var_dump($webp);
$webp 返回 true,但是当我尝试在 Chrome 中查看 webp-image 时,它只显示空白,但大小正确。如果我改为加载图像并使用 PHP(见下文)设置标题,它会显示出来,但颜色错误(黄色太多)。
$im = imagecreatefromwebp('example.webp');
header('Content-Type: image/webp');
imagewebp($im);
imagedestroy($im);
如果我使用命令行转换相同的图像,它会按预期工作。
cwebp -q 100 example.jpg -o example.webp
我正在 Ubuntu 14、Apache 2.4.7 和 PHP 5.5.9-1ubuntu4.4 上对此进行测试。
【问题讨论】:
-
嗯..好的。它并不能解释我对白色 jpeg -> webp 的问题 :(.
-
我一直在尝试这个,最高 1920x1440 的图像似乎工作得很好。加载较大的图像,显示片刻然后就变成空白。图像大小是正确的。我当前的内存限制是 128M,但是当我将它设置为 256M 时也没有帮助。
-
@StefanEdberg:我正在从 webp tp jpg 转换。转换后,即使我在图片中面临太多黄色。我该如何避免这种情况。请帮助..
-
你解决过这个问题吗?我也遇到了同样的问题。
-
不,自从我写了这个问题以来,我没有看过任何东西。对不起。