Problem/Motivation

AVIF image file format is getting traction in browsers' support.

Write up with examples https://jakearchibald.com/2020/avif-has-landed/

This issue is proposing to implement support to this image format in Drupal core's GD Toolkit.

When this issue was opened, browser support for AVIF was roughly 62%. It's now roughly 94%. This is getting close to the level of support for WEBP, which is roughly 96%, and is the format Drupal uses for image styles in the standard profile.

Done:

Proposed resolution

Extend the GD toolkit to support AVIF too.

Remaining tasks

Figure out what to do about the fact that AVIF has to be compiled into PHP and that automatic detection is hard.

https://github.com/libgd/libgd/issues/782

https://github.com/php/php-src/pull/7526

User interface changes

new conversion format available for image effect "convert"

API changes

no

Data model changes

no

Release notes snippet

GDToolkit now supports the AVIF image format.

Issue fork drupal-3202016

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

mondrake created an issue. See original summary.

mondrake’s picture

benmorss’s picture

Thanks for creating this issue... this is exciting!

The relevant libgd release is on its way.

I imagine Drupal uses PHP's getimagesize() function, which will need support here as you mention... is that right? Is anything else needed?

mondrake’s picture

Yes, that's right. We'll then need a PHP version compiled with AVIF support released, and a DrupalCI testbot running it to allow testing. Unless we want to take a different implementation path than what happened for WebP.

mondrake’s picture

Issue summary: View changes

libgd 2.3.2 released today

andypost’s picture

Issue summary: View changes

Updated IS with existing issue for PHP https://bugs.php.net/bug.php?id=78832

mondrake’s picture

Issue summary: View changes

There’s a GitHub PR to add Avif support to getimagesize, https://github.com/php/php-src/pull/5127

benmorss’s picture

There's already a PR to add AVIF support to getimagesize()? That's spectacular!

Talking to PHP core maintainers this weekend, I learned that PHP's GD diverged from libgd long ago. So my libgd PR needs to be adapted for the PHP codebase.

Fortunately that's mostly a matter of allowing it to build with libavif, customizing the main code, and a few other things.

avpaderno’s picture

hestenet’s picture

I will coordinate with @mixologic on the process to make a testbot available.

wim leers’s picture

Super exciting, thanks so much @benmorss! 😊

andypost’s picture

Meantime I used to try use avif via brand new ffi PHP extension https://github.com/andypost/php-ffi-libavif

Looks it's enough just 3 library structures and functions to read size, so promising to get support in PHP 8.1 but then a question of conversion appears...

Right now only imagemagick (not graphicsmagick yet) can be used via dgo.to/imagemagick

PS: PHP pecl extension imagick for PHP 8 just got alpha release

benmorss’s picture

I've started doing the work to propagate the libgd support into PHP's bundled gd fork. The PHP folks tell me there shouldn't be trouble getting this into PHP 8.1.

I just won't get to finish this up until April. (Unless, of course, someone gets inspired to do it sooner 😃)

But, yep, imagemagick already supports AVIF via libheif. I haven't tried out their implementation, so I don't know what they've chosen for encoding defaults and the like.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

andypost’s picture

Issue tags: +PHP 8.1

Support for bundled libgd commited via https://github.com/php/php-src/pull/7026

The implementation AVIF support for getimagesize() and imagecreatefromstring() looks ready, so chances are high to get support in 8.1

benmorss’s picture

Indeed, it's looking good! https://github.com/php/php-src/pull/7091 will add that support, and it's in review right now.

The algorithm I used to determine whether an image's AVIF comes right from Joe Drago, a core maintainer of libavif.

Note that there's no reliable way to determine an AVIF image's size without lots of context, so PHP will simply return 0's for height and width. But it will tell you definitely whether the image's indeed an AVIF.

andypost’s picture

Last brick landed into PHP 8.1! Thank you @benmorss a lot to make it happen!

mondrake’s picture

#17 great news!

PHP [getimagesize()] will simply return 0's for height and width

That's weird... and inconsistent with other image types. But, OK. For the purpose of this issue, this means that AVIF files will not be able to be 'lazy-loaded' like other files. Since the toolkit is invoked also to return height and width, when an AVIF will be in the scope, the toolkit will have to load the file even if it's not going to be manipulated by toolkit ops.

mondrake’s picture

Status: Active » Needs review

First try. Will fail for any PHP below 8.1.

mondrake’s picture

Status: Needs review » Postponed
andypost’s picture

Beta1 ready to be build https://downloads.php.net/~ramsey/

Using --with-avif (requires libavif-dev) and build-in libgd it could be tested (asked @mixologic)

andypost’s picture

Currently only polishing PR left for coming beta-RC times https://github.com/php/php-src/pull/7253

Disable strict pixi requirement for libavif >= 0.9.1
benmorss’s picture

Sorry I missed the recent comments here! @andypost, thanks for trying this out and making comments in the PHP repo as you find things.

To @mondrake:

That's weird... and inconsistent with other image types. But, OK. For the purpose of this issue, this means that AVIF files will not be able to be 'lazy-loaded' like other files.

I agree. Joe Drago, a lead on libavif, has simply told me there's no simple way to reliably get an AVIF image's height and width. Of course, if you link to libavif, you can do it that way. The problem here is that getimagesize() does not use gd.

On the other hand, if you create a GD image with imagecreatefromavif(), you can get its width and height using imagesx() and imagesy(). Does that help at all?

mondrake’s picture

#25 @benmorss yep that's what we need to end up doing. The point here is that imagecreatefromavif() will load to memory the entire image file with IO overhead and possibly its processing before it is available to GD functions. On the web, sometimes (many times) it's sufficient to know h/w to fill in the appropriate html attributes for the <img> tags, so that HTML pages can be rendered appropriately. With other formats, it's very handy to get it via getimagesize() 'cause it won't need to load the entire image file, it's more or less able to get that info from an initial portion of the file, like magics for MIME type identifications.
In #2244359: Lazy-load GD resource in GDToolkit, we made Drupal's GD toolkit load the resource (in PHP 8, the GDImage object) only when the toolkit needs to manipulate it (scaling, resizing, etc etc). With AVIF we'll have to load the image file completely everytime, which is less optimal.

andypost’s picture

@mondrake the imagecreatefromavif() using memory stream implementation IIRC so it will not load whole file when only metadata required

mondrake’s picture

#27 @andypost good then - still we'll have to adjust the toolkit not to lazy load in case of AVIF.

benmorss’s picture

#26 @mondrake yeah, I know it's sadly quite inefficient to go through the overhead of creating the gd image just to get its size. I saw how simple it is for PHP to get dimensions for other types of images. I wish AVIF was the same!

Joe points out that libavif itself doesn't take much work to read an image and get to the point where it knows things like its size. I guess we could use libavif in this way, but I can only imagine the complexities that would come with providing and running a binary along with Drupal 😭

mondrake’s picture

ToolkitGdTest::testManipulations() is a monster that dates back to simpletest when multiple tests were performed in a single method to avoid multiple installations. In the era of Kernel tests, it's better split it in more understandable bits.

The test under 8.1 returns segmentation faults which is not good news.

benmorss’s picture

Your test hit a segfault?

Have you reported that in the PHP project? It sounds concerning.

mondrake’s picture

There’s still too much noise in Drupal core itself running on PHP 8.1, I wouldn’t start pulling my hair yet.

I am waiting for AVIF support to be available on GitHub Actions https://github.com/shivammathur/php-builder/issues/12 so to do some isolated tests there.

andypost’s picture

@mondrake you could use Alpinelinux testing repo to build your image

docker run --rm alpine:edge sh -c 'apk add -X https://dl-cdn.alpinelinux.org/alpine/edge/testing php81 php81-gd && php81 --ri gd'
...
(21/30) Installing aom-libs (3.1.2-r0)
(22/30) Installing libdav1d (0.9.2-r0)
(23/30) Installing libavif (0.9.2-r2)
...
gd

GD Support => enabled
GD Version => bundled (2.1.0 compatible)
FreeType Support => enabled
FreeType Linkage => with freetype
FreeType Version => 2.11.0
GIF Read Support => enabled
GIF Create Support => enabled
JPEG Support => enabled
libJPEG Version => 8
PNG Support => enabled
libPNG Version => 1.6.37
WBMP Support => enabled
XPM Support => enabled
libXpm Version => 30411
XBM Support => enabled
WebP Support => enabled
BMP Support => enabled
AVIF Support => enabled
TGA Read Support => enabled

Directive => Local Value => Master Value
gd.jpeg_ignore_warning => 1 => 1
benmorss’s picture

@mondrake, as far as getimagesize() goes, tentative good news: some folks at Google who specialize in AVIF are working on writing something compact that could be used to get the size of an AVIF image. If they succeed, I'll submit a patch for PHP 8.2.

andypost’s picture

I think we could add extra logic around getimagesize() because AVIF could have a set of image sizes so making "thumbnails" logic needs changes to select the most optimized base to apply imagestyle's plugins

mondrake’s picture

Se we definitely have a segmentation fault with AVIF. I suspect it's when saving an AVIF image to storage, since converting an AVIF to a GIF/PNG/WEBP works (even if we do not have the expected colors at corners). I also suspect it is due to saving to a stream wrapper.

EDIT - segfault is not related to stream wrapper - it's just imageavif() failing.

mondrake’s picture

@benmorss re #31 it looks like this is already known, https://bugs.php.net/bug.php?id=81217

mondrake’s picture

It would be good to do also #3116611: Add a requirements check for GD support of allowed image types before this issue. New image types add new requirements in terms of libraries to be available, we do not really have ways to prevent WSODs at the moment if the GD toolkit tries to call 'expected' functions that are however not compiled in.

benmorss’s picture

@mondrake, is this then caused by the lack of an AVIF codec?

If so, it was fixed in the GD project . I've asked Pierre if he could replicate this work in PHP....

mondrake’s picture

I do not know, but that seems a possibility. Is there an issue on github or php.net we can link here?

andypost’s picture

@mondrake @benmorss I did fix it only in alpine:edge with https://git.alpinelinux.org/aports/commit/?id=e4fba93fd9d83f520645469cae...

Moreover version of "libavif" in alpine 3.14 is 0.9.1 so I asked maintainer to upgrade it https://gitlab.alpinelinux.org/alpine/aports/-/merge_requests/25866

andypost’s picture

I'm packaging skilldlabs/php:81 image and it works for me

$ docker run --rm skilldlabs/php:81 php -r 'var_dump(imageavif(imagecreatetruecolor(8, 8), "/tmp/test"));'
bool(true)
andypost’s picture

@benmorss any idea why libavif is not displaying version of library via phpinfo() I think it could be handy looking like other image-types doing it

$ php --ri gd

gd

GD Support => enabled
GD Version => bundled (2.1.0 compatible)
FreeType Support => enabled
FreeType Linkage => with freetype
FreeType Version => 2.11.0
GIF Read Support => enabled
GIF Create Support => enabled
JPEG Support => enabled
libJPEG Version => 8
PNG Support => enabled
libPNG Version => 1.6.37
WBMP Support => enabled
XPM Support => enabled
libXpm Version => 30411
XBM Support => enabled
WebP Support => enabled
BMP Support => enabled
AVIF Support => enabled
TGA Read Support => enabled

Directive => Local Value => Master Value
gd.jpeg_ignore_warning => 1 => 1
benmorss’s picture

@mondrake re #41... thanks for adding that to alpine!

This AVIF support has been designed to work with libavif with version >=0.8.2. Though of course later is better.

I realize that we didn't require a particular version of libavif in PHP. Should change that.

benmorss’s picture

@andypost #44: it's because we never added this to phpinfo() 🙄.

Looks like that would be a simple change to gd.c. When I get a minute, I can submit a PR.

andypost’s picture

Filed PR https://github.com/php/php-src/pull/7526 to simplify debug

mondrake’s picture

I spinned off the refactoring of ToolkitGdTest into a issue of its own, #3239935: Refactor ToolkitGdTest.

In HEAD this test is in pretty miserable state, it's very hard to add image types to the tests; the refactoring I started here would be helpful for readability regardless of adding AVIF. Reviews appreciated ;)

andypost’s picture

FYI displaying of version string for libraries only possible when PHP is built with bundled GD

mondrake’s picture

Title: Let GDToolkit support AVIF image format » [PP-3] Let GDToolkit support AVIF image format
Issue summary: View changes

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

andypost’s picture

Support for getimagesize() just yet commited

andypost’s picture

Version: 9.4.x-dev » 10.0.x-dev
Related issues: +#3264819: Require PHP 8.1 for Drupal 10.0.0-alpha2
catch’s picture

Is this now [PP-2]?

andypost’s picture

Title: [PP-3] Let GDToolkit support AVIF image format » [PP-1] Let GDToolkit support AVIF image format
Issue tags: +Needs issue summary update

I bet it depends on only one child issue

andypost’s picture

Title: [PP-1] Let GDToolkit support AVIF image format » Let GDToolkit support AVIF image format
Status: Postponed » Needs work

Not sure it should be blocked on tests refactoring

Avif is bundled in 8.1 or disabled as other formats are

mondrake’s picture

@andypost retargeted MR to D10, feel free to take this over

xjm’s picture

Discussed with @catch and @andypost. This issue requires PHP 8.1, so cannot be backported to 9.5. That means we would not have branch parity between 10.0 and 9.5 for this functionality. However, if no deprecations are required to add support for it, it could theoretically be backported to 10.0.x if it is ready in time for the beta deadline. It can also go into 10.1.x.

Per @catch:

The worst that could happen is a module or profile including it in default config for an image style and breaking 9.4/9.5 compatibility.

Realistically it'll be hard for sites to use it until all the browsers support it. It's bad enough with webp on old Mac OS versions. But it's good to have it available.

Tagging for RM review so we can evaluate it one final time before committing to 10.0.x without 9.5.x.

mondrake’s picture

Issue tags: +PHP 8.2

Note: full getimagesize() support for AVIF is only added in PHP 8.2

https://github.com/php/php-src/commit/38460c2c94a0d4b110060951a1a5657522...

mondrake’s picture

Issue summary: View changes
mondrake’s picture

Version: 10.0.x-dev » 10.1.x-dev
mondrake’s picture

Assigned: Unassigned » mondrake

Working on the rebase.

mondrake’s picture

Issue summary: View changes

We would also need a PHP 8.2 bot to test getimagesize() on AVIF returns proper height and width.

mondrake’s picture

Issue summary: View changes

We also need a PHP instance compiled with libavif support. See also https://github.com/shivammathur/php-builder/issues/12

That's likely the reason for the 'Segmentation fault' test failures in latest version of the MR.

mondrake’s picture

Title: Let GDToolkit support AVIF image format » [PP-3] Let GDToolkit support AVIF image format
Status: Needs work » Postponed

See issue summary.

mondrake’s picture

Assigned: mondrake » Unassigned
andypost’s picture

In related issue I've explained how to add this support #3283449-17: Create a DrupalCI Environment for PHP 8.2

Moreover you can use alpinelinux php8/php81 packages which has support, also there's pre-build docker images we are using https://hub.docker.com/r/skilldlabs/php/tags/?page=1&name=81

mondrake’s picture

Title: [PP-3] Let GDToolkit support AVIF image format » [PP-2] Let GDToolkit support AVIF image format
Issue summary: View changes
mondrake’s picture

Issue summary: View changes
mondrake’s picture

Issue summary: View changes
pere orga’s picture

Note that AVIF images are terribly slow to create, and are usually suitable to be generated offline. As Drupal generates image styles when the page loads, that could actually harm the visitor experience the first time.

Ideally, AVIF images could be generated when images are uploaded (I think in WordPress they are trying to do that).

JPEG XL format would be more suitable for online conversion, but unfortunately is still unsupported in all browsers.

andypost’s picture

@Pere Orga true, the creation is not that fast but there's enough solutions in contrib to pre-generate/warm images.
Moreover there's #2986669: Split ImageStyle into the config entity and a separate event-based image processing service

Mixologic’s picture

I've updated both the 8.1 and 8.2 containers to use debian bullseye now, so we should have a more modern version of avif compiled in.

mondrake’s picture

@Mixologic great thanks! Rebased, let’s see now how it flies.

andypost’s picture

Re-queued as phantomjs failed

mondrake’s picture

Albeit small, we do have progress after #73. Now the AVIF image saving tests no longer produce a segmentation fault, but a more palatable

imageavif(): avif error - Could not encode image: No codec available

So we still have a problem with availability of the codec to actually save GD to an AVIF file - https://bugs.php.net/bug.php?id=81217

AVIF support seems still too fragile to me... how many real world PHP 8.1 installations out there will have all the dots and the bars to support it? For sure we need to put in place whatever we can to detect possible issues, after #3116611: Add a requirements check for GD support of allowed image types will be in.

hestenet’s picture

A new testing environment called: "9.3.x-dev test with PHP 8.1 & MySQL 5.7 w/Bullseye Upgrades" has been added, which may be useful here.

andypost’s picture

@hestenet I did rebase but there's no way run new pipeline as issue using Merge Request

sorry https://www.drupal.org/pift-ci-job/2446376 after sometime it said MR is mergeable and allowed to start custom

andypost’s picture

Sadly tests fail even more

Drupal\KernelTests\Core\Image\ToolkitGdTest::testCreateImageFromScratch
with data set #4 (19)
    imageavif(): avif error - Could not encode image: No codec available
hestenet’s picture

@andypost - ah bummer. Any guesses what else we might need to configure to get the codec in there properly?

benmorss’s picture

Just wandering back in here for a minute, without having seen the details of your work - so if this comment is irrelevant, please ignore.

But did you build libavif with a codec? When I worked with it, I remember using aom.

andypost’s picture

It needs both aom-dev and dav1d-dev to build libavif to support encode and decode

In Alpinelinux we use https://gitlab.alpinelinux.org/alpine/aports/-/blob/master/main/libavif/...

mondrake’s picture

Would it be possible to detect WITHIN PHP if libavif is built with such libraries? gd_info() is only checking if GD was compiled with libavif AFAICS, regardless of codecs being included or not

andypost’s picture

@mondrake I filed https://github.com/libgd/libgd/issues/782 and related PR to PHP but both needs work

andypost’s picture

Using the patch from https://github.com/php/php-src/pull/7526 I see following output

$ php --ri gd

gd

GD Support => enabled
GD Version => bundled (2.1.0 compatible)
....
WebP Support => enabled
BMP Support => enabled
AVIF Support => enabled
AVIF Version => 0.10.1
AVIF Codecs => dav1d [dec]:1.0.0, aom [enc/dec]:v3.4.0
TGA Read Support => enabled

EDIT I bet dav1d is optional as aom already provides decoder

mondrake’s picture

Issue summary: View changes

Thank you for #85, I added a comment to the github PR - please lobby there :)

mondrake’s picture

Issue summary: View changes
mondrake’s picture

Issue summary: View changes

Since the feature is targeting D10.1, the conditional support based on PHP version is no longer relevant. Updating IS.

andypost’s picture

8.2 CI image is ready now so requeued https://www.drupal.org/pift-ci-job/2488891

mondrake’s picture

Title: [PP-2] Let GDToolkit support AVIF image format » [PP-1] Let GDToolkit support AVIF image format
Issue summary: View changes
mondrake’s picture

Issue summary: View changes
mondrake’s picture

Title: [PP-1] Let GDToolkit support AVIF image format » Let GDToolkit support AVIF image format
Status: Postponed » Needs review
Related issues: +#2583041: GD toolkit & operations should catch \Throwable to fail gracefully in case of errors

So the patch per se is OK now, what we miss is Codec implemented in the bots' PHP instances. With Codec installed, it should be green.

With PHP 8.1. this has a knock-out effect of a segfault when trying to save the image; with PHP 8.2, an error is thrown, which is better, at least with #2583041: GD toolkit & operations should catch \Throwable to fail gracefully in case of errors we'd probably be able to prevent WSOD.

PHP misses a solution to self-detect if AVIF is fully supported or not, unfortunately. Right now, with no codec, the status report will still tell you that AVIF is supported.

hestenet’s picture

DrupalCI's PHP 8.1 and 8.2 containers have been recompiled, they now have both libavf and libaom:

Hopefully that does it, but let us know if it looks like anything else should be added to the container.

mondrake’s picture

Thank you! I rerun the tests - they still fail, though. We’re still at the same status as in #92.

mondrake’s picture

Just throwing a thought (beware: not a PHP build expert :))

Could it be this is because the bot's PHP instances use the bundled GD library, and not the externally linked one? That's at least my take from #2921123-65: Adjust Rectangle class to calculate rotated image dimensions according to libgd 2.2.2+. In that case, that seems not the usual case on *nix machines, see comment https://github.com/php/php-src/pull/7526#issuecomment-1214957123

andypost’s picture

PHP should be built with bundled GD but it needs configuration --with-avif + see #41
https://git.alpinelinux.org/aports/tree/community/php81/APKBUILD#n266

andypost’s picture

Filed MR to finally fix libavif #3283449-37: Create a DrupalCI Environment for PHP 8.2

TL'DR library needs suffix to be installed from backports

hestenet’s picture

Requeued tests on the MR to see if changes from #3283449-44: Create a DrupalCI Environment for PHP 8.2 work..

mondrake’s picture

Issue summary: View changes

The 8.1 test run is green, and the 8.2 one is not failing on the GdToolkit test -> AVIF is now working on the bots!! Thanks to @andypost, @Mixologic and @hestenet for the great work here and in Slack

The biggest question now is: do we want to support AVIF right now, when getting PHP setup right is non-trivial, and it's not possible to detect if all bits and pieces are correctly in place? gd_info() can tell us if AVIF is enabled, but that's not enough: if the codec is not installed, there is no way to understand it until an error occurs e.g. trying to save an AVIF image.

mondrake’s picture

andypost’s picture

Trying to save file when no encoder enabled will throw but it looks like weird way to test codec absence

hestenet’s picture

The biggest question now is: do we want to support AVIF right now, when getting PHP setup right is non-trivial, and it's not possible to detect if all bits and pieces are correctly in place? gd_info() can tell us if AVIF is enabled, but that's not enough: if the codec is not installed, there is no way to understand it until an error occurs e.g. trying to save an AVIF image.

I think coming up with some form of automatic detection of support (+ really good documentation) is going to be crucial, given how tough it was for us to get all the pieces together even in our test environments.

mondrake’s picture

some form of automatic detection of support

that's what https://github.com/libgd/libgd/issues/782 and https://github.com/php/php-src/pull/7526 would tentatively provide, respectively for GDlib and PHP embedded GD. But they both seem still quite far, and will likely be addressed only in future versions of both...

andypost’s picture

andypost’s picture

added the todo-link and rebased for current 10.1.x

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new149 bytes

The Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

mondrake’s picture

Status: Needs work » Needs review

Rebased

andypost’s picture

it's RTBC IMO but needs summary update and CR, probably release note as well

kim.pepper’s picture

Issue summary: View changes

Added a simple CR and RN snippet https://www.drupal.org/node/3348348

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new89 bytes

The Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

andypost’s picture

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

Rebased and applied suggestion for strict comparison

quietone’s picture

FYI, it seem there are problems with the diff.

$ git ac https://git.drupalcode.org/project/drupal/-/merge_requests/936.diff
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  7846    0  7846    0     0  20701      0 --:--:-- --:--:-- --:--:-- 20701
error: missing binary patch data for 'core/tests/fixtures/files/img-test.avif'
error: binary patch does not apply to 'core/tests/fixtures/files/img-test.avif'
error: core/tests/fixtures/files/img-test.avif: patch does not apply
mstrelan’s picture

@quietone that seems like a gitlab issue. The .patch URL (instead of .diff) shows the binary content of the avif file.

quietone’s picture

@mstrelan, thanks. I forgot about the .patch version

catch’s picture

I think we can add support independently, but both this and the existing webp support make #3213491: Add fallback format support to responsive images more important so that sites can actually use it. Adding as a related issue.

Does the GD toolkit already handle whether the webserver has support for AVIF - i.e. does it only show in the list of options if it's actually going to work?

andypost’s picture

Related issues:

The check was added in #3116611: Add a requirements check for GD support of allowed image types

but not every place in core using the filtered list of formats, probably there was an issue about add general requirements check

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new89 bytes

The Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

andypost’s picture

Status: Needs work » Needs review

There's binary file in patch, so to apply patch it needs to download it and apply using git apply 936.patch or use patch -p1 -i 936.diff (it should be downloaded https://git.drupalcode.org/project/drupal/-/merge_requests/936.diff using .diff instead of .patch)

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new89 bytes

The Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

nod_’s picture

Status: Needs work » Needs review
Issue tags: +no-needs-review-bot
mondrake’s picture

@catch re #116 - yes the toolkit will tell if AVIF is available, but that check is unfortunately not enough. In order to have FULL support, PHP needs to be compiled with an AVIF codec, and that’s non-trivial, see #100 and #103; besides, there’s no way to detect automatically if the codec is installed, see #104.

catch’s picture

Issue summary: View changes

Thanks @mondrake I had read that earlier in the issue but had forgotten about it by now - I've added both of those to the issue summary. Also thanks to @andypost for opening them and working on them!

I wonder a bit if we should do some kind of kludgy support detection by catching the error in the meantime until those issues are fixed (or at least until AVIF is more widely available?), not sure where to put that though and if it's expensive we might have to cache the results or something.

andypost’s picture

Meantime animated AVIS added to latest Firefox https://www.mozilla.org/en-US/firefox/113.0/releasenotes/

jwilson3’s picture

Given the bleeding edge support (php 8.2) for AVIF, and complexity in it being compiled into PHP, it occurred to me that there should be an option to work around those limitations in contrib space. Alas, there is no conversion image style effect feature that I could find, so I opened up a feature request in what seemed like the most logical place to put it.

#3360072: Add an AVIF conversion image styles effect

Sadly that module doesn't seem like it has been getting a lot of love, use, or maintenance for a few years now.

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

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs followup

Can MR be updated for 11.x

Also open thread mentions needing a follow up if that could be created also before the new branch is made.

smustgrave’s picture

Issue tags: -Needs followup

Reading wrong commit forget the follow-up part.

mondrake’s picture

@andypost done, I guess this needs a rebase now

andypost’s picture

Status: Needs work » Needs review

Rebased

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Changes look good and all tests green.

mondrake’s picture

Status: Reviewed & tested by the community » Needs work

Unfortunately there’s no solution for #124 yet, and IMHO getting this in as it is now would be very fragile.

NW for #124.

NOTE: the Imagemagick toolkit is a working alternative (as long as the Imagemagick binary can support AVIF itself).

andypost’s picture

Rebased and sqashed commits into 2 for 11.x branch

andypost’s picture

Filed upgrade of PHP 8.3 CI image to latest Debian stable, AVIF is shipped now with libaom dependency fixed

https://git.drupalcode.org/project/drupalci_environments/-/merge_request...

andypost’s picture

Issue summary: View changes

Updated is with https://jakearchibald.com/2020/avif-has-landed/ which perfectly explains benefits

andypost’s picture

I think we can add to reports if no AVIF support available so people can read logs to get why imagecreatefromavif() or imageavif() are not found to solve #124

mstrelan’s picture

I think we can add to reports if no AVIF support available so people can read logs to get why imagecreatefromavif() or imageavif() are not found to solve #124

Unfortunately these functions still exist, even if avif is not supported. I did find the following code (found in https://bugs.php.net/bug.php?id=81217) would trigger a warning:

$ php -r 'var_dump(imageavif(imagecreatetruecolor(8, 8), "/tmp/test"));'
PHP Warning:  imageavif(): AVIF image support has been disabled
 in Command line code on line 1

I've tried to test for this in the status report using a pattern I found in \Drupal\Core\Render\ElementInfoManager::buildInfo. This works in my very limited test of two environments, one supporting AVIF, one not.

mondrake’s picture

Rebased

luksak’s picture

I needed that for AVIF to work with imagemagick, but probably that is needed for GD as well: #3362088: ExtensionMimeTypeGuesser doesn't support .avif

mondrake’s picture

Status: Needs work » Needs review
Issue tags: +Needs change record updates

I put some caching around @mstrelan solution + added some info in status report if AVIF write support is broken.

This fits #124 I think so back to NR.

IMHO the CR should be expanded with some hints on how to fix the lack of the codec or of the binding of libavif. That’s above me though, help appreciated.

smustgrave’s picture

Status: Needs review » Needs work

Not sure correct status, but #141 mentions change record updates. Which is technically apart of the review process.

mondrake’s picture

php/php-src just committed Image format detection false positives with external GD #12019. This will likely only hit PHP 8.4.

andypost’s picture

Core's CI images are not yet using external GD https://git.drupalcode.org/project/drupalci_environments/-/blob/producti...

--with-external-gd Use external libgd

andypost’s picture

Status: Needs work » Needs review
Issue tags: -Needs change record updates

Not sure CR should elaborate how specific distros can install codec if it missing, it's unrelated to core

smustgrave’s picture

Brought up in #needs-review-queue-initative in slack. Was mentioned by @catch that

detection logic is still in progress

and that parts will need the release manager review.

smustgrave’s picture

Wonder if anyone has any update for the previous comment?

jwilson3’s picture

IMHO the CR should be expanded with some hints on how to fix the lack of the codec or of the binding of libavif.

I also don't know much about fixing this by compiling PHP, but I can add that the avif contrib module allows selection of different processors beyond just the GD option, including https://github.com/kornelski/cavif-rs (via the avif_lib add-on module). So maybe the CR could point people to the issue I linked above if they're not able to compile PHP with the codec support on their hosting environment. #3360072: Add an AVIF conversion image styles effect

larowlan’s picture

Status: Needs review » Needs work
Issue tags: -PHP 8.1, -Needs release manager review +Needs change record updates

The code here looks good to me.

The needs release manager review tag was added in 9.x era when we were discussing min PHP requirements.

I don't think we need it anymore - especially as we're into 11.x territory where 8.2+ will be available.

I think the remaining tasks here are to update the CR with instructions for folks on how to add avif support to their version of PHP

Tagging as NW for that.

Great work here folks

heddn’s picture

Status: Needs work » Needs review
Issue tags: -PHP 8.2, -Needs change record updates

We are in Drupal 11.1-land now. Which will require PHP 8.3. I've updated the related CR to include libavif installation instructions. Back to NR.

andypost’s picture

Merged 11.x and removed PHP 8.2 related workaround

I simplified check to prevent checking avif writes if no readonly support

smustgrave’s picture

Status: Needs review » Needs work

Moving to NW for open questions on MR.

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

acbramley’s picture

Status: Needs work » Needs review

All threads resolved and a green pipeline 🥳

heddn’s picture

Status: Needs review » Reviewed & tested by the community

LGTM. All concerns addressed.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

Made a couple of suggestions on the issue.

andypost’s picture

Status: Needs work » Needs review

Thank you, applied clean-up!

andypost’s picture

btw it could use follow-up to add UI to configure quality and speed for images in terms of #3372932: [Meta] High-performance images (nearly) out of the box

ref https://www.php.net/manual/function.imageavif.php

alexpott’s picture

Status: Needs review » Needs work

Added some more comments to the MR.

andypost’s picture

I see no reason to use cache except of static variable because this check should happen only once while PHP is running

andypost’s picture

Status: Needs work » Needs review

Removed cache as this kind of checks should be cached statically, also removed useless logging of error

andypost’s picture

Thanks Alex! I did rebase on top of 11.x and reverted all unrelated changes

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Believe feedback for this one has been addressed

mstrelan’s picture

Would be great to get this in 11.2

mstrelan’s picture

Issue summary: View changes

Added some info to the issue summary about browser support, which is now around 94%.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed
Issue tags: -11.2.0 release priority +11.2.0 release notes

Committed 71c58d6 and pushed to 11.x. Thanks!

Fixed gitattributes on commit to make .avif files easier to manage - this resolves #113

diff --git a/.gitattributes b/.gitattributes
index e7b792f8407..f9e806c9a10 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -48,6 +48,7 @@ core/.phpstan-baseline.php text eol=lf whitespace=blank-at-eol,-blank-at-eof,-sp
 # Define binary file attributes.
 # - Do not treat them as text.
 # - Include binary diff in patches instead of "binary files differ."
+*.avif    -text diff
 *.eot     -text diff
 *.exe     -text diff
 *.gif     -text diff

  • alexpott committed 71c58d67 on 11.x
    Issue #3202016 by mondrake, andypost, acbramley, mstrelan, hestenet,...

  • alexpott committed 75ea9ab7 on 11.x
    Issue #3202016 follow-up by alexpott: Let GDToolkit support AVIF image...

Status: Fixed » Closed (fixed)

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

longwave’s picture

This is more of a highlight than something that needs a release note.