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

php webp转jpg的方法介绍

藏色散人
藏色散人 原创
2020-10-15 10:30:28 3256浏览

php webp转jpg的方法:首先打开相应的代码文件;然后调用系统库;最后通过“if($ext=='webp'){...}”方式将webp转jpg即可。

推荐:《PHP视频教程

相关介绍:WebP(发音:weppy)是一种同时提供了有损压缩与无损压缩(可逆压缩)的图片文件格式,派生自影像编码格式VP8,被认为是WebM多媒体格式的姊妹项目,是由Google在购买On2 Technologies后发展出来,以BSD授权条款发布。

JPEG(Joint Photographic Experts Group)是JPEG标准的产物,该标准由国际标准化组织(ISO)制订,是面向连续色调静止图像的一种压缩标准。 JPEG格式是最常用的图像文件格式,后缀名为.jpg或.jpeg。

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核实处理。