Convert JPG/PNG Image to WEBP Using PHP

In this post, we are going to learn how to convert JPG/PNG images to WEBP images.

WebP is a modern image format that provides superior lossless and lossy compression for images on the web. Using WebP, webmasters and web developers can create smaller, richer images that make the web faster. The WebP format reduces file size more than standard JPEG compression while maintaining similar or better image quality.

WebP is natively supported in Google Chrome, Firefox, Edge, the Opera browser, and by many other tools and software libraries. Developers have also added support to a variety of image editing tools.


<h1 style="text-align:center;">Convert JPG/PNG Image to WEBP Using PHP</h1>

$file = '2.png';
$image = imagecreatefromstring(file_get_contents($file));
$cont = ob_get_contents();
$content = imagecreatefromstring($cont);
$output = 'images/output.webp';
echo '<h4>Output Image Saved as '.$output.'</h4>';

Follow this video for complete guidance :

Recommended For You

About the Author: Ritesh Ghimire

Ritesh is a Computer Engineer, Web Developer and an active cricket follower.