如何将webP图像格式转换为正常?PHP

dav*_*vid 2 php image webp

我有一个ios和android应用程序.有时用户将webP图像上传到我的服务器.问题是ios从我的服务器下载时无法显示此图像.

所以我想检查我的PHP代码.如果图像是webP格式.然后我将它转换为png格式.

我怎么能用PHP做到这一点?

Usa*_*jaz 12

现在已经晚了,但仅仅是为了它.它只能使用PHP完成.没有任何外部工具.

引自PHP.net 文档:

<?php
// Load the WebP file
$im = imagecreatefromwebp('./example.webp');

// Convert it to a jpeg file with 100% quality
imagejpeg($im, './example.jpeg', 100);
imagedestroy($im);
?>
Run Code Online (Sandbox Code Playgroud)

所以我假设您可以使用imagepng()代替示例中的imagejpeg.


n00*_*dl3 5

使用libwebp :( 我假设$file是绝对路径并libwebp已安装)

$regex="/^(.*)(\.webp)$/";
if(preg_match($regex, $file)){
   $out=preg_replace($regex, "${1}.png", $file);
   exec("dwebp $file -o $out");
}
Run Code Online (Sandbox Code Playgroud)

没有测试,但应该工作......