php webp轉(zhuǎn)jpg的方法:首先打開相應(yīng)的代碼文件;然后調(diào)用系統(tǒng)庫(kù);最后通過(guò)“if($ext=='webp'){…}”方式將webp轉(zhuǎn)jpg即可。
推薦:《PHP視頻教程》
相關(guān)介紹:WebP(發(fā)音:weppy)是一種同時(shí)提供了有損壓縮與無(wú)損壓縮(可逆壓縮)的圖片文件格式,派生自影像編碼格式VP8,被認(rèn)為是WebM多媒體格式的姊妹項(xiàng)目,是由Google在購(gòu)買On2 Technologies后發(fā)展出來(lái),以BSD授權(quán)條款發(fā)布。
JPEG(Joint Photographic Experts Group)是JPEG標(biāo)準(zhǔn)的產(chǎn)物,該標(biāo)準(zhǔn)由國(guó)際標(biāo)準(zhǔn)化組織(ISO)制訂,是面向連續(xù)色調(diào)靜止圖像的一種壓縮標(biāo)準(zhǔn)。 JPEG格式是最常用的圖像文件格式,后綴名為.jpg或.jpeg。
php webp轉(zhuǎn)jpg
最近做個(gè)項(xiàng)目,涉及到摳圖,
但是webp格式的到火狐上顯示不了
解決方案:
//webp轉(zhuǎn)換成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); }
官網(wǎng)上都有說(shuō)明,具體就是這樣了,
但是這樣有個(gè)不便之處,收費(fèi),尼瑪,坑爹的,所以采用了另外一種方式。
調(diào)用系統(tǒng)庫(kù),代碼如下,趕腳很高大上的樣子
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); }