avif error - Could not encode image: No codec available

Created on 27 June 2025, 18 days ago

Problem

Drupal core fills the logs with PHP warnings if the AVIF codec is not available.

Full message:

Warning: imageavif(): avif error - Could not encode image: No codec available\n in /path/to/drupal/web/core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php line 565 (Drupal\\Core\\Entity\\EntityStorageException)"

It's only a warning, but it's annoying and resource consuming, and broke our test suite. :-)

Steps to reproduce

Install Drupal on a machine that doesn't have the necessary AVIF support (Debian 11 is an easy way to test), make an image upload field, upload an image, check the logs.

πŸ› Bug report
Status

Active

Version

11.2 πŸ”₯

Component

image system

Created by

πŸ‡«πŸ‡·France greg.harvey

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @greg.harvey
  • πŸ‡³πŸ‡ΏNew Zealand quietone

    If this problem was discovered on a version of Drupal that is not 11.x, add that information in the issue summary and leave the version at 11.x. In Drupal core changes are made on on 11.x (our main development branch) first, and are then back ported as needed according to the Core change policies β†’ . Also mentioned on the version β†’ section of the list of issue fields documentation. Thanks.

  • πŸ‡«πŸ‡·France greg.harvey

    Done, thank you.

  • First commit to issue fork.
  • πŸ‡¬πŸ‡§United Kingdom nicrodgers Monmouthshire, UK

    We were experiencing this php warning in our behat test suite after upgrading from 11.x to 11.2

    It's caused by a combination of old linux system (in this case, Debian 11) and PHP misbehaving.

    On affected systems, you can reproduce the error by running

    $ php -r 'var_dump(imageavif(imagecreatetruecolor(8, 8), "/tmp/test"));'
    PHP Warning:  imageavif(): avif error - Could not encode image: No codec available  in Command line code on line 1
    Warning: imageavif(): avif error - Could not encode image: No codec available  in Command line code on line 1
    bool(true)
    

    As you can see, php thinks it has avif support because it's returning true (you can also see this in the phpinfo output within the gd section) but the reality is that it's unable to create avif files because the codec is missing and gives that warning.

    There's a bug on php.net for it:
    https://bugs.php.net/bug.php?id=81217

    The php bug has been closed as not a PHP bug - they say:

    So, it seems that the root cause of this issue is that the libaom versions currently provided by Debian APT and Alpine APK systems are not functional (AFAIK they are compiled without the required BUILD_SHARED_LIBS=1, but I may be wrong here).
    So, in order to make imageavif() and imagecreatefromavif() work, you need to do everything by hand:

    1. compile and install libaom
    2. compile and install libdav1d (to decode AV1)
    3. compile and install libyuv (used by libavif to better handle YUV decoding)
    4. compile and install libavif
    5. compile and install the gd PHP extension (with the --with-avif flag)

    For an example about how that can be done in Debian (so, Ubuntu too) and Alpine, you can take a look at https://github.com/mlocati/docker-php-extension-installer

    Personally I think the php team are being dismissive here. Clearly it is a bug that could be better handled in php, because on the one hand php is saying YES, AVIF is supported here, and then on the other, when you try to use it it errors out because the codec is missing. But we are where we are.

    For Drupal, I think the easy fix here is to suppress the warning from the imageavif() command within checkAvifSupport(). The function correctly returns FALSE on the affected systems so I think it's fine to suppress the php warning.

  • Pipeline finished with Success
    12 days ago
    Total: 481s
    #537945
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Temped to tag for tests but don't know what they would be, but summary still needs to be updated please.

Production build 0.71.5 2024