Fix fatal error when trying to resize animated WebP using GD

This commit is contained in:
Kijin Sung 2024-03-19 22:15:13 +09:00
parent d519cd2516
commit 13e8445309
2 changed files with 18 additions and 1 deletions

View file

@ -568,7 +568,7 @@ class FileHandler
{
$source = @imagecreatefrombmp($source_file);
}
elseif ($type === 'webp' && function_exists('imagecreatefromwebp'))
elseif ($type === 'webp' && function_exists('imagecreatefromwebp') && !Rhymix\Framework\Image::isAnimatedWebP($source_file))
{
$source = @imagecreatefromwebp($source_file);
}

View file

@ -47,6 +47,23 @@ class Image
return $frames > 1;
}
/**
* Check if a file is an animated WebP.
*
* @param string $filename
* @return bool
*/
public static function isAnimatedWebP(string $filename): bool
{
if (!$fp = @fopen($filename, 'rb'))
{
return false;
}
$buff = fread($fp, 64);
fclose($fp);
return preg_match('/^RIFF....WEBPVP8X[\x00-\xff]{14}ANIM/s', $buff) > 0;
}
/**
* Get image information
*