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); }