How To Convert GIF To WebP Image Format In PHP With Example?

function yttags_gif2webp($src_file_path, $file_destination_path, $compression_qty = 100)
{
    $image = imagecreatefromgif($src_file_path);
    imagepalettetotruecolor($image);
    $final_output = imagewebp($image, $file_destination_path, $compression_qty);
    if (false === $final_output) {
        return false;
    }
    imagedestroy($image);
    return $file_destination_path;
}

Function usage:

echo yttags_gif2webp('img/oldfile.gif','img/newfile.webp',100);

Leave a Comment