5

I recently upgraded my PHP version to 8.1-fpm and also upgraded Debian to Bullseye. I read somewhere that Bullseye comes with AVIF support but when I try to use imageavif(), I get the following error:

PHP message: PHP Fatal error:  Uncaught Error: Call to undefined function imageavif()

I ran "php -i | grep AVIF" on my server and it returns:

ImageMagick supported formats => 3FR, 3G2, 3GP, AAI, AI, APNG, ART, ARW, AVI, AVIF, AVS, BGR, BGRA, BGRO, BIE, BMP, BMP2, BMP3, BRF, CAL, CALS, CANVAS, CAPTION, CIN, CIP, CLIP, CMYK, CMYKA, CR2, CR3, CRW, CUR, CUT, DATA, DCM, DCR, DCX, DDS, DFONT, DNG, DPX, DXT1, DXT5, EPDF, EPI, EPS, EPS2, EPS3, EPSF, EPSI, EPT, EPT2, EPT3, ERF, FAX, FILE, FITS, FRACTAL, FTP, FTS, G3, G4, GIF, GIF87, GRADIENT, GRAY, GRAYA, GROUP4, H, HALD, HDR, HEIC, HISTOGRAM, HRZ, HTM, HTML, HTTP, HTTPS, ICB, ICO, ICON, IIQ, INFO, INLINE, IPL, ISOBRL, ISOBRL6, J2C, J2K, JBG, JBIG, JNG, JNX, JP2, JPC, JPE, JPEG, JPG, JPM, JPS, JPT, JSON, K25, KDC, LABEL, M2V, M4V, MAC, MAGICK, MAP, MASK, MAT, MATTE, MEF, MIFF, MKV, MNG, MONO, MOV, MP4, MPC, MPG, MRW, MSL, MTV, MVG, NEF, NRW, NULL, ORF, OTB, OTF, PAL, PALM, PAM, PATTERN, PBM, PCD, PCDS, PCL, PCT, PCX, PDB, PDF, PDFA, PEF, PES, PFA, PFB, PFM, PGM, PGX, PICON, PICT, PIX, PJPEG, PLASMA, PNG, PNG00, PNG24, PNG32, PNG48, PNG64, PNG8, PNM, POCKETMOD, PPM, PREVIEW, PS, PS2, PS3, PSB, PSD, PTIF, PWP, RADIAL-GRADIENT, RAF, RAS, RAW, RGB, RGBA, RGBO, RGF, RLA, RLE, RMF, RW2, SCR, SCT, SFW, SGI, SHTML, SIX, SIXEL, SPARSE-COLOR, SR2, SRF, STEGANO, SUN, TEXT, TGA, THUMBNAIL, TIFF, TIFF64, TILE, TIM, TTC, TTF, TXT, UBRL, UBRL6, UIL, UYVY, VDA, VICAR, VID, VIDEO, VIFF, VIPS, VST, WBMP, WEBM, WEBP, WMV, WPG, X, X3F, XBM, XC, XCF, XPM, XPS, XV, XWD, YCbCr, YCbCrA, YUV

How do I get imageavif() to work? Am I missing something?

Edit: I ran the function "print_r(gd_info());" and this is the resulting array:

Array
(
    [GD Version] => 2.3.0
    [FreeType Support] => 1
    [FreeType Linkage] => with freetype
    [GIF Read Support] => 1
    [GIF Create Support] => 1
    [JPEG Support] => 1
    [PNG Support] => 1
    [WBMP Support] => 1
    [XPM Support] => 1
    [XBM Support] => 1
    [WebP Support] => 1
    [BMP Support] => 1
    [AVIF Support] => 
    [TGA Read Support] => 1
    [JIS-mapped Japanese Font Support] => 
)

Seems like I have GD but its AVIF support isn't set. How do I get it to support AVIFs?

Also, I am currently using imagewebp() and that function works just fine.

Edit: Thanks to Nico Haase for pointing me to the GitHub issue for Ondřej Surý's PHP repository - https://github.com/oerdnj/deb.sury.org/issues/1641

In the meantime, is there anything I can do to get imageavif() to work that wouldn't be too excessive or is it best to just wait?

kmoser
  • 8,780
  • 3
  • 24
  • 40
user1413341
  • 226
  • 3
  • 17
  • 1
    `imageavif()` doesn't use ImageMagick/`Imagick`. It uses GD. You'll need to install `php-gd` (or something like that). – gen_Eric Dec 17 '21 at 19:38
  • 1
    Looks like I have GD - updated question with more info. – user1413341 Dec 17 '21 at 20:36
  • 1
    Show us your PHP ini. and look yourself if the extension is enabled. (phpinfo() ) – Itay Moav -Malimovka Dec 17 '21 at 20:39
  • 1
    Does https://php.watch/versions/8.1/gd-avif help? Did you also install `libavif`? Also, how did you install PHP? Bullseye ships 7.4, it does not contain 8.1 – Nico Haase Dec 17 '21 at 20:41
  • Okay - so I tried `apt install libavif-dev` and I get the message `libavif-dev is already the newest version`. Do I need to do the `./configure` part as well? If so, that part is confusing and ambiguous. For example, `For production systems, make sure to enable other extensions as well.` - does that mean I need to explicitly enable webp even though it's already enabled and if I don't, it'll become disabled? I wish that step was written more clearly. Also, it doesn't explain the `./buildconf` command at all. Plus, the link to `How to compile PHP` goes to a massive confusing document. – user1413341 Dec 18 '21 at 02:17
  • You don't need to compile PHP on your own - but how did you install PHP in the first place? Bullseye does not ship 8.1 – Nico Haase Dec 18 '21 at 07:08
  • I just manually installed it. – user1413341 Dec 18 '21 at 07:53
  • What does that mean? Compiling from source? Using any other repository? – Nico Haase Dec 18 '21 at 18:48
  • Oh, I use Ondřej Surý's repository at packages.sury.org/php – user1413341 Dec 18 '21 at 20:46
  • 1
    Then https://github.com/oerdnj/deb.sury.org/issues/1641 should help: there's an open bug report for the missing support – Nico Haase Dec 18 '21 at 20:51
  • Ah, I see. Thanks! Guess I'll just wait until it's addressed then. Nothing I can do now, right? – user1413341 Dec 18 '21 at 22:47

1 Answers1

1

GD extension depends on the libavif package to provide the underlying AVIF codecs. GD extension requires libavif version 0.8.2 or higher.

Ubuntu/Debian

apt install libavif-dev

RHEL/Fedora

dnf install libavif-devel

Once the dependencies are installed, PHP can be compiled with AVIF support with the new --with-avif flag in the ./configure script.

./buildconf --force
./configure --enable-gd --with-avif

Note that the ./configure command above is just an example; For production systems, make sure to enable other extensions as well.

Source: https://php.watch/versions/8.1/gd-avif

Roman Zaykovsky
  • 493
  • 5
  • 12