search
HomeBackend DevelopmentPHP ProblemIntroduction to the method of converting php webp to jpg

php webp to jpg method: first open the corresponding code file; then call the system library; finally convert webp to jpg through "if($ext=='webp'){...}" method Can.

Introduction to the method of converting php webp to jpg

Recommended: "PHP Video Tutorial"

Related introduction: WebP (pronounced: weppy) is An image file format that provides both lossy compression and lossless compression (reversible compression). It is derived from the image encoding format VP8 and is considered a sister project of the WebM multimedia format. It was developed by Google after purchasing On2 Technologies and is based on BSD Release of licensing terms.

JPEG (Joint Photographic Experts Group) is the product of the JPEG standard, which was developed by the International Organization for Standardization (ISO) and is a compression standard for continuous-tone still images. JPEG format is the most commonly used image file format, with the suffix .jpg or .jpeg.

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

There are instructions on the official website, this is the specifics,

But there is an inconvenience, the fee, oh, it’s a rip-off, so Another approach was adopted.

Call the system library, the code is as follows, it 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 Introduction to the method of converting php webp to jpg. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft