php webp转jpg

在项目中遇到WebP格式图片在火狐浏览器无法显示的问题。本文提供两种解决方法:1) 使用CloudConvert API进行转换,但需付费;2) 调用系统库进行转换,代码实现简单高效。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

但是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);

 }


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值