Problem/Motivation

Drupal version affected is 11.2.1.

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.

Steps to reproduce

Proposed resolution

Suppress the warning from the avif support check. This won't be fixed in PHP in the near future: https://bugs.php.net/bug.php?id=81217

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Issue fork drupal-3532792

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

greg.harvey created an issue. See original summary.

quietone’s picture

Version: 11.2.x-dev » 11.x-dev
Issue summary: View changes

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.

greg.harvey’s picture

Issue summary: View changes
greg.harvey’s picture

Done, thank you.

nicrodgers made their first commit to this issue’s fork.

nicrodgers’s picture

Status: Active » Needs review

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.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs issue summary update

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

swentel’s picture

Hmm, more or less related or not? We're getting "AVIF image support has been disabled" in our logs, which seems to be a warning from PHP. cf https://bugs.php.net/bug.php?id=81217

Status page at Drupal does say it's supported: Supported image file formats: GIF, JPEG, PNG, WEBP, AVIF

Kind of annoying the watchdog is now being filled with these logs. Not sure what approach is best here for better testing it will actually work :)

mstrelan’s picture

Issue summary: View changes
Status: Needs work » Needs review
Issue tags: -Needs issue summary update

I think this is one of those cases where we are better off just getting the bug fixed rather than trying to work out how to test it. Updated proposed resolution.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

that's fair, then this should be straight forward.

catch’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Needs work

Agreed we don't need tests here, however I think we should add an inline comment above this line explaining why we're suppressing the error with a link to the php bug report to make it easier for someone to figure out why we're doing it.

nicrodgers’s picture

Status: Needs work » Needs review

I've added an inline comment as per @catch's suggestion above.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs Review Queue Initiative

feedback appears to be addressed.

  • catch committed 5da08af3 on 11.2.x
    Issue #3532792 by nicrodgers, greg.harvey: avif error - Could not encode...

  • catch committed 240fe874 on 11.x
    Issue #3532792 by nicrodgers, greg.harvey: avif error - Could not encode...
catch’s picture

Version: 11.x-dev » 11.2.x-dev
Status: Reviewed & tested by the community » Fixed

Committed/pushed to 11.x and cherry-picked to 11.2.x, thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.