3

I'm getting this PHP "E_ERROR: gd-webp cannot allocate temporary buffer" when trying to save a webp image from an URL.

$image = imagecreatefromwebp('https://thumbs.gfycat.com/JointUnnaturalEnglishsetter.webp');

According to the PHP docs, imagecreatefrontwebp can load the file source by URL. What does that error mean?

Cat
  • 396
  • 1
  • 5
  • 13
  • 1
    The error is most likely due to the fact that the image is animated. With static pictures there is no such problem. – ScreamX Apr 23 '20 at 18:59
  • So does it mean that PHP GD cannot save animated webp images? – Cat Apr 23 '20 at 23:28
  • See error report https://github.com/libgd/libgd/issues/648 and subscripte to be informed about changes. ;) – user706420 Nov 24 '21 at 14:34

2 Answers2

4

imagecreatefromwebp does not support animated WebP as of PHP version <= 8 you can see the documentation

enter image description here

0

I noticed that webp files created by PHP 5.x imagewebp() (eg. by reading in a JPG and outputting as WEBP) - with no animation or transparency (Alpha channel) - were not able to be decoded either by Windows (7 with google's webp patch) or by PHP imagecreatefromwebp(). The latter would return the following messages: gd-webp cannot allocate temporary buffer ... is not a valid WEBP file

I then upgraded to PHP 8.1, and now when I output the same images from imagewebp() they are now read fine by both Windows 7 and by imagecreatefromwebp().

Thus it appears that older PHP versions have an issue where imagewebp() outputs some 'questionable' data which does not prevent browsers such as FF or Brave from properly displaying the image, but does prevent PHP 8.1's imagecreatefromwebp() from being able to decode the file.

David G
  • 106
  • 6