yireo / magento2-avif

yireo/magento2-avif

Magento 2 module to add AVIF support to the Magento frontend

magento2-module Compatibility: 2.4.7-2.4.9 Code Quality: Fail Tests: Fail Security: Pass OSL-3.0

Magento 2 module for AVIF

Magento version
PHP version
License
Latest Version

This module adds AVIF support to Magento 2, as a convertor for Yireo NextGenImages. It ships with the following features:

  • Local JPEG and PNG images in the frontend are converted to AVIF and added as <source type="image/avif"> within a <picture> element, with the original image as fallback;
  • AVIF sources are added before other next-gen formats (like WebP from Yireo_Webp2), so that browsers prefer AVIF;
  • srcset candidates are converted as well;
  • AVIF images are only encoded again when the original image is newer;
  • PNG transparency is kept;
  • Configurable quality level and encoding speed, per store view;
  • The admin shows whether PHP GD supports AVIF;
  • Luma swatches in product listings update the AVIF source.

Requirements

  • PHP GD compiled with AVIF support (libavif). Check this via php -r 'var_dump(function_exists("imageavif"));' or in the admin under Stores > Configuration > Yireo > Yireo AVIF. Without it, the module does nothing: the original images are shown as before.

Known limitations

  • The Luma product gallery (Fotorama) and Hyvä are not supported yet;
  • AVIF encoding is slow. Images are converted when a page is first rendered, so the first request to a page with many new images is slow.

See also:

Requesting support

Feel free to open an Issue here on GitHub. However, do make sure to be thorough. See SUPPORT.md for further details.

Current status

Static Tests
Unit Tests
Integration Tests
Playwright
DI Compilation

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog,
and this project adheres to Semantic Versioning.

[Unreleased]

[0.9.9] - 25 November 2026

Fixed

  • Prevent path traversal and srcset injection: only JPEG/PNG files inside pub/media, pub/static or var/tmp are converted and srcset descriptors and URLs are validated
  • Reject images above 40 megapixels before decoding them, to prevent memory exhaustion
  • Write AVIF images atomically via a temporary file and lock conversion per target image
  • Keep absolute server paths out of exception messages
  • Hide the AVIF test page /avif/test/images outside of developer mode, unless the hidden setting yireo_avif/test/enabled is set
  • Validate AVIF quality level and encoding speed when saving the configuration
  • Fail with a clear error when the AVIF target folder is missing or not writable
  • Turn errors for missing source images into regular conversion errors instead of uncaught exceptions

[0.9.8] - 16 November 2026

Fixed

  • Require NextGenImages 0.5.16 and declare used modules only
  • Update AVIF source with the AVIF image of the selected swatch
  • Reuse up-to-date AVIF images and verify conversion
  • Add missing ACL resource Yireo_Avif::config

Added

  • Add quality, encoding speed and AVIF support status

[0.9.7] - 22 October 2025

Fixed

  • Add proper support AVIF via GD even though this causes conversion issues most of the time

[0.9.6] - 8 April 2025

Fixed

  • Compat psr/log with Magento 2.4.7
Versions
Version Stability QA Status Compatibility Released
0.9.9 stable Fail Magento 2.4.7-2.4.9 Details 2026-11-25 15:51:49
0.9.8 stable Fail Magento 2.4.7-2.4.9 Details 2026-11-16 19:29:51
0.9.7 stable Pass Not yet tested Details 2025-10-22 11:37:53
0.9.6 stable Not tested Not yet tested Details 2024-04-08 10:14:49

Requires 8

Package Constraint
ext-gd *
ext-pcre *
magento/framework ^101.0.1|^101.1|^102.0|^103.0
magento/module-backend ^100.0|^101.0|^102.0
magento/module-config ^101.0.0|^101.1.0
magento/module-store ^101.0
php >=8.2 <8.6
yireo/magento2-next-gen-images ^0.5.16

Requires-dev 6

Package Constraint
bitexpert/phpstan-magento ^0.42
ext-json *
loki/magento2-functional-tests @dev
phpstan/phpstan ^2.0
phpunit/phpunit ^9.0|^10.0|^11.0
yireo/magento2-integration-test-helper ~0.0

Suggests 1

Package Reason
magento/module-swatches Update AVIF sources when switching swatches in product listings

Compatibility

Each Magento release line is installed on its supported PHP versions, then the module is built (DI compilation + static-content deploy) and its unit and integration suites are run. The matrix shows the lines and PHP versions the module is confirmed to install and run on. Code-quality results further down (phpstan, phpcs, …) are reported separately and never affect compatibility.

Compatibility matrix (Magento × PHP)
Magento PHP 8.2 PHP 8.3 PHP 8.4 PHP 8.5
2.4.7 Pass Pass
2.4.8 Pass Pass
2.4.9 Pass Pass

Code Quality

Advisory checks against the module's source. Static analysis runs once across the whole module; PHPStan re-runs per Magento + PHP version because resolvable symbols differ between releases. These NEVER affect the Compatibility badge. A phpcs finding can't make a module incompatible.

Static analysis

Coding standards (phpcs), mess detection (phpmd), copy-pasted code (cpd), PHP cross-version compatibility, composer.json validity. Each runs once for the whole module.

Static analysis results
Tool Status Findings Summary
PHPCS Fail 31 2 errors, 29 warnings (ruleset: Magento2)
PHPMD Warning 4 4 rule violations (ErrorControlOperator:2, UnusedFormalParameter:1, TooManyPublicMethods:1)
Cpd Pass 0
Composer validate Info 1 valid; 1 advisory note (composer validate --strict)

PHPStan

Type-checks the module's PHP against a real Magento install at the configured gate level. Re-runs per Magento and PHP version because resolvable symbols differ between releases.

PHPStan results by Magento and PHP version
Magento PHP 8.2 PHP 8.3 PHP 8.4 PHP 8.5
2.4.7 Error Error
2.4.8 15 15
2.4.9 15 15

Tests

Unit and integration suites, run for each applicable Magento and PHP version. A test failure speaks to the module's behaviour, not its compatibility with a Magento line, so it is reported here separately and never reddens the compatibility matrix.

Unit tests

Unit tests results by Magento and PHP version
Magento PHP 8.2 PHP 8.3 PHP 8.4 PHP 8.5
2.4.7 N/A N/A
2.4.8 N/A N/A
2.4.9 N/A N/A

Integration tests

Integration tests results by Magento and PHP version
Magento PHP 8.2 PHP 8.3 PHP 8.4 PHP 8.5
2.4.7 Error Error
2.4.8 Pass Pass
2.4.9 Pass Pass

Security

Security checks run directly against the module: an audit of its declared dependencies for known vulnerabilities (composer audit) and a scan of its source for malware and web-shell signatures. Each runs once. A malware detection fails the version outright.

Security results
Tool Status Findings Summary
Composer audit N/A 0 no resolvable dependency tree to audit: Your requirements could not be resolved to an installable set of packages. Problem 1
Malware scan Pass 0

More from yireo

View vendor
Make it pay

Turn an existing module into recurring revenue.

If you already maintain a Magento 2 module on GitHub or GitLab, listing it on Packagento takes about five minutes. We mirror your tags, handle distribution signing, and route paid licenses through Stripe Connect, so you can keep shipping the way you already do.