PHP8.1.21版本已发布
vue8.1.21版本已发布
jquery8.1.21版本已发布

php webp如何转换jpg

藏色散人
藏色散人 原创
2020-08-25 10:32:52 3232浏览

php webp转换jpg的方法:1、使用“webptojpgapi”方法将webp转换成jpg格式;2、调用系统库来实现webp转换jpg,代码如“@system("dwebp $img_pathwebp -o $pic_path"”。

推荐:《PHP视频教程》

php webp转jpg

最近做个项目,涉及到抠图,

但是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);
 }
声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。