Home > Article > Backend Development > How to convert jpg in php webp
php Method for converting webp to jpg: 1. Use the "webptojpgapi" method to convert webp to jpg format; 2. Call the system library to convert webp to jpg, with code such as "@system("dwebp $img_pathwebp -o $pic_path"".
Recommended: "PHP Video Tutorial"
php webp to jpg
I recently worked on a project that involved cutout,
but the webp format cannot be displayed on Firefox
Solution:
//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); }
All available on the official website Explanation, this is the specific,
But this has the inconvenience, charging, damn, cheating, so I adopted another method.
Call the system library, the code is as follows, He looks very classy
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); }
The above is the detailed content of How to convert jpg in php webp. For more information, please follow other related articles on the PHP Chinese website!