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);
}
以上就是php webp怎样转换jpg的细致内容,更多请关注ki4网别的相干文章!
收藏 | 0