最近做个项目,涉及到抠图,
但是webp格式的到火狐上显示不了
解决方案:
//webp转换成jpg格式
function webptojpgapi($inputurl,$inputname){
$apiurl = "https://api.cloudconvert.com/convert?apikey=[自己的apikey]&input=download&filename=$inputname&download=false&save=true&inputformat=webp&outputformat=jpg&file=$inputurl";
$res = file_get_contents($apiurl);
$res = json_decode($res,true);
return $res['output']['url'].'/'.str_replace('webp','jpg',$inputname);
}
官网上都有说明,具体就是这样了,
但是这样有个不便之处,收费,尼玛,坑爹的,所以采用了另外一种方式。
调用系统库,代码如下,赶脚很高大上的样子
if($ext=='webp'){ $img_pathwebp = "Runtime/yy_".time().rand_string(3).'.png'; @file_put_contents($img_pathwebp, file_get_contents($img_path)); $img_pathwebp = realpath($img_pathwebp); $pic_path = $img_pathwebp ; @system("dwebp $img_pathwebp -o $pic_path", $retval); }