Search code examples
phpimagewebp

How to convert webP image format to normal ? php


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?


Solution

  • Using libwebp: ( I assume $file is an absolute path and libwebp is installed)

    $regex="/^(.*)(\.webp)$/";
    if(preg_match($regex, $file)){
       $out=preg_replace($regex, "${1}.png", $file);
       exec("dwebp $file -o $out");
    }
    

    Didn't test, but should work...