介绍相关发音一种

php webp转jpg的方法介绍

编程开发 2020-10-16 08:19:22 45

导读

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

相关介绍: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);
 }


1253067 TFnetwork_cn