Plugins: AVIF Image Support

Plugins: AVIF Image Support

AVIF on PHP Server

Ako želiš da kreiraš AVIF odnosno da konvertuješ u i iz AVIF formata, na serveru je neophodno da imaš ili GD Library ili ImageMagick PHP module, kao PHP: Image Processing and Generation - Manual

GD library is mostly installed by default but it doesn’t support AVIF manipulation in PHP 7.4

apt install php{7.4,8.1,8.2}-gd

if you want AVIF manipulation, this is suggested as it even works for PHP 7.4

apt install php{7.4,8.1,8.2}-imagick

There is PHP support now to confirm with phpinfo() or php -i | grep AVIF. GD: AVIF image support - PHP 8.1 • PHP.Watch

If you need a fast library, the fastest one is libvips, which also supports SVG, WebP, and AVIF. For PHP integration, you can refer to the php-vips repository on GitHub.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
cat /etc/php/8.3/fpm/conf.d/20-gd.ini

# prikaži odakle se koristi neki package
apt-cache policy php8.3
update-alternatives --config php

add-apt-repository ppa:ondrej/php

# obriši sve što je bilo ranije
apt list --installed | grep php8.3
dpkg --remove --force-depends php8.3 php8.3-{apcu,bcmath,bz2,cli,common,curl,fpm,gd,gmp,imap,imagick,intl,mbstring,mysql,opcache,pspell,readline,soap,sqlite3,tidy,xml,xmlrpc,xsl,zip}

# or automatic in one line
dpkg --remove --force-depends $(apt list --installed | grep -o '^php8.3[^ /]*')

# sad instaliraj, koji će biti povučen iz novo repo
apt install php8.3
dpkg --install php8.3
apt --fix-broken install php8.3 php8.3-{apcu,bcmath,bz2,cli,common,curl,fpm,gd,gmp,imap,imagick,intl,mbstring,mysql,opcache,pspell,readline,soap,sqlite3,tidy,xml,xmlrpc,xsl,zip}

php
update-alternatives --config php

Želim da fiksiram da se samo php8.3 instalira iz ondrej repository:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
cat << EOF | sudo tee /etc/apt/preferences.d/ondrej-php.pref
Package: php8.3*
Pin: release o=LP-PPA-ondrej-php
Pin-Priority: 2000

Package: php*
Pin: release o=LP-PPA-ondrej-php
Pin-Priority: 100
EOF

cat << EOF | sudo tee /etc/apt/preferences.d/ondrej-nginx-mainline.pref
Package: *
Pin: release o=LP-PPA-ondrej-nginx-mainline
Pin-Priority: 1100
EOF

Kad sam već počeo, hajdemo i na HTTP/3:

1
2
3
4
5
6
7
8
# nginx mainline is stable and latest
add-apt-repository ppa:ondrej/nginx-mainline

cat << EOF | sudo tee /etc/apt/preferences.d/ondrej-nginx-mainline.pref
Package: *
Pin: release o=LP-PPA-ondrej-nginx-mainline
Pin-Priority: 1100
EOF

ali to neće da može jer CloudPanel verzija koristi pagespeed i ima i te direktive.

AVIF Image File Format

Focus on WebP as AVIF is mostly NOT supported on mobile

It is available in PHP 8.X

How to Use AVIF: The New Next-Gen Image Compression Format — Lightspeed

AVIF has landed - JakeArchibald.com


Modern Images WP | adamsilverstein/wordpress-modern-images to set default image format used for sub-sized images generated by WordPress. On ne radi ništa posebno, već samo dodaje MIME tipove (hook: mime_types) i samo poziva hook: “image_editor_output_format” čime definiše format na output. I vezano za konverziju, on to ne radi i uopšte ne proverava da li će konverzija biti uspešna niti menja output tagove već obezbećuje da su pravilni tagovi u HTML-u. Sama konverzija se radi standardnim PHP toolovima (GD, ali ne i sa ImageMagick itd). Čak je i AVIF podržan u novom PHP-u.

Avif Express sa repo na Pijushgupta/avif-express: Wordpress plugin to convert jpg,png and webp to avif and render them se bavi i konverzijom i serving ali serving samo tako što menja images na proper format. Moraš da instaliraš direktno sa GitHub preko https://codeload.github.com/Pijushgupta/avif-express/zip/refs/heads/main URL. Poseduje najosnovniku bulk konverziju a za sve konverzije koristi Imagick a kao backup GD Library dok opcija Cloud nije stvarno definisana nego neki custom developed. Radi, ali ustvari slike generiše on-the-fly (ali ima i opciju “Disable on the fly avif conversion”), i menja u IMG tagu sve na avif, ali ne generiše . Na kraju se ispostavilo da ustvari sve radi. Podešavanja su vrlo misleading pošto “Disable on the fly avif conversion (recommended)” ustvari znači “Turn off AVIF”, tako da ne isključuj.

AVIF Support | AVIF Uploader ume da konvertuje sve u AVIF ako imaš podršku na serveru, a pregledao sam i vrlo je ok kodirano. Ne bavi se servovanjem niti išta slično, ali prilikom upload-a kreira AVIF, a pruža i podešavanje kvaliteta konverzije. Tu se nalazi i onaj “server check” koji proverava AVIF capabilities. Dakle, ovo je za kreiranje prilikom upload.

The plugin Imghaste is fascinating for its implementation of modern image formats, including AVIF and WebP. To ensure compatibility with caching plugins, plugin utilizes a Service Worker to intercept and serve images that are supported by the client. This allows for seamless integration with images in CSS files and those requested via Ajax. Overall, Imghaste is a highly intriguing plugin that warrants further analysis.


Maximally optimizing image loading for the web

Ideal and proper AVIF and WebP encoding quality settings i testiranje AVIF and WebP image quality settings


WebP & AVIF Converter je plugin sa repo na korneliuszburian/webp-avif-converter, koga sam slučajno pronašao tako što lik kompletno objavio kod za plugin - php - WordPress Plugin for WebP/AVIF Image Conversion - Code Review Stack Exchange, ali samo za konverziju formata prilikom upload-a. Nema skoro nikakve opcije, ali je uspešno uradio kreiranje oba formata prilikom upload-a.

The WebP Converter for Media also supports AVIF in the Pro version, which can be found on GPL sites. To activate the Pro version in the GPL version, you can use any string as an access token. It uses either the GD library or Imagick for conversion and can perform server HTML rewriting for serving proper image by utilizing an interesting “PassThru” mode that creates webpc-passthru.php with the use of ob_start. Images are saved in a separate directory /uploads/uploads-webpc, and that’s also configurable. Additionally, it supports AVIF, but only in the Pro version and it adds a useful option for regenerating thumbnails in the Media Library. The issue I’ve had is that it didn’t work with the AVIF format - it reported as “crashed”, while everything else worked very well. Useful snippet Nginx configuration for the WebP Converter for Media WordPress plugin - Useful Snippets.

The Squidge plugin on the ainsleyclark/squidge repository is insteresting as it’s supports AVIF and can also utilize local tools via shell. It can generate <picture> tags using the squidge_image helper function and can be set up with either nginx or apache rules. However, it seems that the plugin is no longer actively developed. It also offers a WP-CLI command to regenerate everything at once. Nema mnogo korisnika pa mislim da je prestao da troši vreme na to.

Image Type Converter je od iste firme koja pravi “AVIF Support” plugin, a omogućava konverziju slika, bez načina serve-ovanja, tako što imaš link pored slike (pun reklama) a tek u Pro verziji može da radi na upload kao i bulk.


You can add the MIME type for AVIF like this, as seen in plugin “WR Allow Modern Images”:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
# Add support for modern AVIF image formats

add_filter('upload_mimes', fn($mime) => $mime + [
  'heic'  => 'image/heic',
  'heif'  => 'image/heif',
  'heics' => 'image/heic-sequence',
  'heifs' => 'image/heif-sequence',
  'avif'  => 'image/avif',
  'avifs' => 'image/avif-sequence',
]);

WordPress 6.5 adds AVIF support  – Make WordPress Core

date 17. Jan 2020 | modified 14. Jun 2024
filename: Plugins » Uploads » Images » Formats » AVIF