How to convert webP image format to normal ? php

david picture david · Jun 30, 2015 · Viewed 7.4k times · Source

I have an ios and android application. sometime the users upload webP image to my server. the problem is ios can't show this image when it's downloaded from my server.

so I want to check within my php code. if the image is webP format . then i will convert it to png format.

How could i do that using php?

Answer

Usama Ejaz picture Usama Ejaz · Mar 11, 2017

It's late but just for the sake of it. It can be done using PHP only. Without any external tool.

Quoted from PHP.net documentation:

<?php
// Load the WebP file
$im = imagecreatefromwebp('./example.webp');

// Convert it to a jpeg file with 100% quality
imagejpeg($im, './example.jpeg', 100);
imagedestroy($im);
?>

So I assume you can use imagepng() instead of imagejpeg that is in the example.