php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #81217 imageavif() fails - Segmentation Fault or No codec available
Submitted: 2021-07-01 15:04 UTC Modified: 2021-10-15 17:35 UTC
From: mlocati at gmail dot com Assigned: cmb (profile)
Status: Not a bug Package: GD related
PHP Version: 8.1.0alpha2 OS: Debian Buster and Alpine Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
31 - 6 = ?
Subscribe to this entry?

 
 [2021-07-01 15:04 UTC] mlocati at gmail dot com
Description:
------------
I tried the brand new imageavif() function, but I can't make it work.

# On Debian Buster

Launch a docker container with
docker run --rm -it php:8.1.0alpha2-cli-buster bash
Run these commands:

$ echo 'deb http://deb.debian.org/debian buster-backports main' >/etc/apt/sources.list.d/buster-backports.list
$ apt-get update
$ apt-get install -y libfreetype6-dev libjpeg62-turbo-dev libpng-dev libxpm-dev libwebp-dev libavif-dev
$ docker-php-ext-configure gd --enable-gd --with-webp --with-jpeg --with-xpm --with-freetype --with-avif
$ docker-php-ext-install -j$(nproc) gd
$ php --ri gd

gd

GD Support => enabled
GD Version => bundled (2.1.0 compatible)
FreeType Support => enabled
FreeType Linkage => with freetype
FreeType Version => 2.9.1
GIF Read Support => enabled
GIF Create Support => enabled
JPEG Support => enabled
libJPEG Version => 6b
PNG Support => enabled
libPNG Version => 1.6.36
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
$ php -r 'var_dump(imageavif(imagecreatetruecolor(8, 8), "/tmp/test"));'
Segmentation fault


# On Alpine Linux 3.14

Launch a docker container with
docker run --rm -it php:8.1.0alpha2-cli-alpine3.14 sh
Run these commands:

$ apk add freetype-dev libjpeg-turbo-dev libpng-dev libxpm-dev libwebp-dev libavif-dev
$ docker-php-ext-configure gd --enable-gd --with-webp --with-jpeg --with-xpm --with-freetype --with-avif
$ docker-php-ext-install -j$(nproc) gd
$ php --ri gd

gd

GD Support => enabled
GD Version => bundled (2.1.0 compatible)
FreeType Support => enabled
FreeType Linkage => with freetype
FreeType Version => 2.10.4
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

$ php -r 'var_dump(imageavif(imagecreatetruecolor(8, 8), "/tmp/test"));'

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



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-07-01 15:10 UTC] cmb@php.net
Yes, you need a codec for libavif.  Try installing libaom.

I think we need to do checks for encoding and decoding in
config.m4.
 [2021-07-01 15:29 UTC] mlocati at gmail dot com
I tried recompiling gd on Debian Buster after adding libaom:

apt-get install -y libfreetype6-dev libjpeg62-turbo-dev libpng-dev libxpm-dev libwebp-dev libavif-dev libaom-dev

But

php -r 'var_dump(imageavif(imagecreatetruecolor(8, 8), "/tmp/test"));'

still gives a Segmentation fault



I also tried recompiling gd on Alpine Linux 3.14 after adding aom:

apk add freetype-dev libjpeg-turbo-dev libpng-dev libxpm-dev libwebp-dev libavif-dev aom-dev

but 

php -r 'var_dump(imageavif(imagecreatetruecolor(8, 8), "/tmp/test"));'

still outputs

Warning: imageavif(): avif error - Could not encode image: No codec available in Command line code on line 1
bool(true)

(and the generated file is empty)
 [2021-07-02 09:39 UTC] cmb@php.net
Hmm, I wonder whether we need to explicitly configure a codec for
libavif on some platforms.  Apparently, pkg-config doesn't do this
here.
 [2021-08-26 14:23 UTC] pear at laurent-laville dot org
This issue is still live with version 8.1.0beta3

Same test procedure, but used docker image php:8.1.0beta3-fpm-buster
 [2021-09-27 17:47 UTC] morss at google dot com
I think this is the same thing that Pierre kindly fixed here:

https://github.com/libgd/libgd/issues/770
 [2021-09-28 00:05 UTC] apostnikov at gmail dot com
I filed MR to upgrade libavif in Alpinelinex 3.14 but looks it needs major version bump for libaom, meantime it should be working in alpine:edge
 [2021-10-08 10:12 UTC] mlocati at gmail dot com
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
 [2021-10-15 17:35 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2021-10-15 17:35 UTC] cmb@php.net
> 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 […]

Right.  Closing as not a (PHP) bug.
 [2022-11-02 21:43 UTC] mlocati at gmail dot com
Just an update on this issue.

Alpine Linux offers the pre-compiled libraries avif/aom/dav1d.

With Alpine up to 3.14, by using these libraries we had this error:

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


But since Alpine 3.15 and later, it seems we can use them without problems, that is:

apk add libavif-dev aom-dev dav1d-dev
 [2024-02-05 10:36 UTC] mlocati at gmail dot com
Update: on Debian 12 (Bookworm) we can use the system-provided libraries:

apt-get install libavif-dev libaom-dev libdav1d-dev

This can't be done on previous Debian versions: invoking imageavif() was leading to this error

Error 2: imageavif(): avif error - Could not encode image: No codec available
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 23 21:01:31 2024 UTC