Problem/Motivation

Call to undefined function Drupal\system\Plugin\ImageToolkit\imageavif() in Drupal\system\Plugin\ImageToolkit\GDToolkit::checkAvifSupport() (line 565 of web/core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php)

Using Drupal 11.2.0-beta1 with only a few contrib modules that are not using the ImageToolkit.

Steps to reproduce

Edit or create a user:

/admin/people/create
/user/edit
or
/user/1/edit

Proposed resolution

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Issue fork drupal-3526690

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

xmacinfo created an issue. See original summary.

xmacinfo’s picture

Issue summary: View changes

It also affects user creation.

xmacinfo’s picture

PHPStorm finds the GD file with the proper function:

/Applications/PhpStorm.app/Contents/plugins/php-impl/lib/php.jar!/stubs/gd/gd.php

I tried clearing the cache a few times to no luck.

Using PHP Version 8.4.6 or PHP 8.3.16, Drupal Status Report PHP info has:

GD Support enabled
GD Version bundled (2.1.0 compatible)

ishani patel’s picture

Hello,
I've followed the steps and checked with D11.1.6, and using PHP Version 8.3.19
But not reproduce the issue.

Thank you!

mstrelan’s picture

You somehow have a php build that is missing the global imageavif function. What happens if you modify that line 565 to $supported = function_exists('imageavif') && imageavif(imagecreatetruecolor(1, 1), $tempFile, 0, 10) && fstat($tempFile)['size'] > 0;

cilefen’s picture

I linked to this issue from #3202016: Let GDToolkit support AVIF image format. Yes it seems like Drupal should check whether the function exists before calling it.

andypost’s picture

Not clear how it possible to by-pass guard function_exists('imageavif') maybe this function exists but disabled somehow

cilefen’s picture

I may be misunderstanding your comment but in Drupal there is not a function_exists check for imageavif.

xmacinfo’s picture

@ishani patel The bug affect only Drupal 11.2.x, not Drupal 11.1.x.

cilefen’s picture

Version: 11.2.x-dev » 11.x-dev

grimreaper’s picture

Hi,

I am encountering the same fatal error on an env without AVIF support.

On status report page, there is a warning about the missing AVIF support but this does not prevent the fatal error.

mondrake’s picture

Priority: Major » Critical
Related issues: +#3524206: Use avif with webp fallback for all core image styles

Given that #3524206: Use avif with webp fallback for all core image styles has practically made AVIF the default for 11.2, I think this will be Critical in case PHP is not binding the avif functions.

mondrake’s picture

xmacinfo’s picture

@grimreaper

Indeed, now I see the status message error message:

GD library

bundled (2.1.0 compatible)

    - Supported image file formats: GIF, JPEG, PNG, WEBP.
    - Unsupported image file format: AVIF.
      Check the PHP GD installation documentation if you want to add support.
    - AVIF is not supported, likely because of PHP missing a codec for encoding images. See the change record for more information.

Not sure why I was not seeing this yesterday.

xmacinfo’s picture

My development stack will not support AVIF for the foreseeable future. Fortunately, my production stack supports AVIF.

AVIF Support enabled

So, we need to make sure the fallback to WEBP works on all user create/edit paths:

admin/people/create
/user/edit
or
/user/1/edit

andypost’s picture

Status: Active » Reviewed & tested by the community

This guard is required

/var/www/html/web $ php -r 'var_dump(function_exists("imageavif"));'
bool(true)
/var/www/html/web $ php -d disable_functions=imageavif -r 'var_dump(function_exists("imageavif"));'
bool(false)

/var/www/html/web $ php -d disable_functions=imageavif -r 'imageavif();'
PHP Fatal error:  Uncaught Error: Call to undefined function imageavif() in Command line code:1
Stack trace:
#0 {main}
  thrown in Command line code on line 1

Fatal error: Uncaught Error: Call to undefined function imageavif() in Command line code:1
Stack trace:
#0 {main}
  thrown in Command line code on line 1

xmacinfo’s picture

Yes, but I do not see a fallback to WEBP.

$supported = function_exists('imageavif') && imageavif(imagecreatetruecolor(1, 1), $tempFile, 0, 10) && fstat($tempFile)['size'] > 0;
fclose($tempFile);

return $supported;

Are we returning FALSE instead of falling back to WEBP?

andypost’s picture

andypost’s picture

@xmacinfo this method is for detection, see the commit from #3524206: Use avif with webp fallback for all core image styles

mstrelan’s picture

@xmacinfo this function is just a check to see if avif is supported. It is called by GDToolkit::supportedTypes and if it returns FALSE then we don't include avif as a supported type. The image_convert_avif plugin checks if avif is supported and creates an avif if it is, and a webp (or whatever else you configure) if not. Agree with the RTBC but would be good for @xmacinfo or @grimreaper to confirm it works with this patch.

grimreaper’s picture

Hi,

I confirm the fix and RTBC on an environment without AVIF support, no more fatal error when displaying a form with an image field like /media/add/image

Thanks!

  • catch committed 93b4f5b4 on 11.2.x
    Issue #3526690 by cilefen, xmacinfo, andypost, grimreaper, mstrelan:...
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!

  • catch committed a00c032c on 11.x
    Issue #3526690 by cilefen, xmacinfo, andypost, grimreaper, mstrelan:...

Status: Fixed » Closed (fixed)

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

damien laguerre’s picture

I get a warning message after installing the 11.2:

Warning: imageavif(): avif error - Could not encode image: No codec available in Drupal\system\Plugin\ImageToolkit\GDToolkit::checkAvifSupport() (line 565 of core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php).

Debian 11 / PHP8.3.
GD library Version => 2.3.3

damien laguerre’s picture

I suggest adding an "@"

$supported = function_exists('imageavif') && @imageavif(imagecreatetruecolor(1, 1), $tempFile, 0, 10) && fstat($tempFile)['size'] > 0;
mondrake’s picture

@damien laguerre would you kindly open a new issue for that, and link it here? This issue is closed and unlikely to be reopened.

greg.harvey’s picture