PHP GD and WebP support:
Normal WebP (VP8): supported since PHP 5.4
Transparent WebP or alpha transparency (VP8X, VP8L): supported since PHP 7.0
Animated WebP (VP8X): not supported at all.
You can use the images from here https://developers.google.com/speed/webp/gallery2
here https://ezgif.com/help/alternative-animated-image-formats
and here https://developers.google.com/speed/webp/gallery1
Test with imagecreatefromwebp('your-image.webp'); and see the errors.
You can detect animated or transparent webp using this code.
<?php
function webpinfo($file) {
if (!is_file($file)) {
return false;
} else {
$file = realpath($file);
}
$fp = fopen($file, 'rb');
if (!$fp) {
return false;
}
$data = fread($fp, 90);
fclose($fp);
unset($fp);
$header_format = 'A4Riff/' . 'I1Filesize/' . 'A4Webp/' . 'A4Vp/' . 'A74Chunk';
$header = unpack($header_format, $data);
unset($data, $header_format);
if (!isset($header['Riff']) || strtoupper($header['Riff']) !== 'RIFF') {
return false;
}
if (!isset($header['Webp']) || strtoupper($header['Webp']) !== 'WEBP') {
return false;
}
if (!isset($header['Vp']) || strpos(strtoupper($header['Vp']), 'VP8') === false) {
return false;
}
if (
strpos(strtoupper($header['Chunk']), 'ANIM') !== false ||
strpos(strtoupper($header['Chunk']), 'ANMF') !== false
) {
$header['Animation'] = true;
} else {
$header['Animation'] = false;
}
if (strpos(strtoupper($header['Chunk']), 'ALPH') !== false) {
$header['Alpha'] = true;
} else {
if (strpos(strtoupper($header['Vp']), 'VP8L') !== false) {
$header['Alpha'] = true;
} else {
$header['Alpha'] = false;
}
}
unset($header['Chunk']);
return $header;
}?>
Reference: https://stackoverflow.com/a/68491679/128761
Usage:
<?php
$info = webpinfo('your-image.webp');
if (isset($info['Animation']) && $info['Animation'] === true) {
echo 'It is animated webp.';
}
if (isset($info['Alpha']) && $info['Alpha'] === true) {
echo 'It is transparent webp.';
}
?>