yireo / magento2-next-gen-images

yireo/magento2-next-gen-images

Magento 2 module to add NextGen images support to the Magento frontend

  • Jisse Reitsma (Yireo)
magento2-module Compatibility: 2.4.7-2.4.8 Code Quality: Warning Tests: N/A Security: Pass OSL-3.0

Magento 2 module for NextGenImages

This module adds next-gen image support to Magento 2. Please note that this is a base extension for other extensions to use. See Yireo_Webp2 for details.

WARNING: If you are using Hyva and want to use the latest version of this module, remove Hyva_YireoNextGenImages.

Development

This module features some settings and info panels in the Magento Store Configuration. But the major feature is a plugin on the Layout that scans for HTML <img/> tags to convert them into <picture/> tags with sources for alternative image formats.

A module Foo_Bar could add a etc/di.xml file to add a new convertor (a class implementing \Yireo\NextGenImages\Convertor\ConvertorInterface) to the convertor listing:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Yireo\NextGenImages\Convertor\ConvertorListing">
        <arguments>
            <argument name="convertors" xsi:type="array">
                <item name="foobar" xsi:type="object">Foo\Bar\Convertor</item>
            </argument>
        </arguments>
    </type>
</config>

FAQ

Can I skip lazy loading of images?

Yes, just add fetchpriority="high" to the image HTML of your choice.

Can I call upon the convertor directly?

Yes, you can. You can inject the class Yireo\NextGenImages\Image\ImageCollector as a block argument via the XML layout (or alternatively use the LokiComponents $viewModelFactory or the Hyva $viewModels to instantiate it) and then call upon it as follows:

$images = $this->imageCollector->collect($imageUrl);

Roadmap

  • Move CLI into separate module
  • Move frontend into separate module
  • Create GraphQL support
  • Add more next gen image formats
    • JPEG 2000
    • HEIC
    • AVIF
    • JPEG XL
    • WebP2

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.5.15] - 22 October 2025

Fixed

  • Fix PHP call
  • Add helper-method for fetching GdImage

[0.5.14] - 24 July 2025

Fixed

  • Add Yireo_IntegrationTestHelper as dep
  • Allow replacing images in AJAX (AHAH) requests as well
  • Add PHP 8.4 testing

[0.5.13] - 23 April 2025

Fixed

  • Fix issue with str_contains under PHP 7.4
  • Fixed implicitly declared nullable arguments, improves compatibility with PHP 8.4

[0.5.12] - 19 February 2025

Fixed

  • Issue with LIBXML_HTML_NOIMPLIED and templates with multiple roots Yireo_Webp2#175

[0.5.11] - 11 February 2025

Fixed

  • Fix possible warning with DOM loading

[0.5.10] - 11 December 2024

Fixed

  • Fix issues from #83
  • Better integration tests

[0.5.9] - 4 December 2024

Fixed

  • Masks and unmasks angle brackets quotes #83 @wilfriedwolf
  • Command next-gen-images:convert not working if images are on shared folders #80 @wilfriedwolf

[0.5.8] - 24 October 2024

Fixed

  • Add funding

[0.5.7] - 26 August 2024

Fixed

  • Wrong composer dependencies

[0.5.6] - 23 August 2024

Fixed

  • Cast string as return type

[0.5.5] - 23 August 2024

Fixed

  • Add CSP nonces to inline scripts

[0.5.4] - 9 August 2024

Fixed

  • Only re-use limited set of HTML attributes for source-tags #78

[0.5.3] - 22 May 2024

Fixed

  • Make sure that HTML attribute values with double-quotes are still working #77

[0.5.2] - 4 April 2024

Fixed

  • Compatibility with Magento >=2.4.7-beta3

[0.5.1] - 27 February 2024

Fixed

  • Add warning about Hyva_YireoNextGenImages because docs are not read
  • Check for image extension in entire url instead of only at the end #72 @jesperingels
  • Remove data-src and data-srcset from original attributes in sources
  • Remove all whitespaces in image output
  • Fix broken integration tests due to modified constructor
  • Add relative-path of source image to target-path if target is cache-folder #62 @rommelfreddy

[0.5.0] - 22 September 2023

Added

  • Dispatch all-purpose Hyva gallery-init event to modify component data
  • Allow to configure skipped layout handles via DI type of ShouldModifyOutput

Fixed

  • Fix issue where image is not replaced with img tag opening plus newline
  • Field in admin is cache_directory_path instead of cache_directory #154
  • Quick hack for supporting /pub/ in URLs

[0.4.1] - 15 August 2023

Fixed

  • Make sure only PNG and JPG are being picked up

Added

  • Moved Hyva compatibility module features into this module, deprecating the compat mod

[0.4.0] - 16 March 2023

Fixed

  • Fixed HTTPS links being reset to HTTP links due to "normalization"
  • Simplify normalization without HTTP/HTTPS reset

Added

  • Option convert_css_backgrounds to convert images in CSS backgrounds as well #25 (@rommelfreddy)

[0.3.18] - 05 March 2023

Fixed

  • Fix deprecated dynamic property

[0.3.17] - 05 March 2023

Fixed

  • Fix PHP 7.3 issue
  • Bump composer requirement to PHP 7.3

[0.3.16] - 01 March 2023

Fixed

  • Make image cache path /media/nextgenimages/ configurable

[0.3.15] - 28 February 2023

Fixed

  • Remove duplicate source that matches original image
  • Also convert data-src when present
  • Support URLs from multiple Store Views
  • Ajax response plugin gets incorrect gallery images #55 @joe-vortex

[0.3.14] - 27 February 2023

Fixed

  • Prevent img in script from being parsed #133

[0.3.13] - 27 February 2023

Fixed

  • Fix for PHP 8.2 deprecated mb_convert_encoding #57 @hostep

[0.3.12] - 10 January 2023

Fixed

  • Remove loading="lazy" when fetchpriority="high" is present #53 @jesperingels

[0.3.11] - 24 October 2022

Fixed

  • Error 'Argument #1 () must not be empty' on PHP 8 #36 @khoimm92

[0.3.10] - 3 July 2022

Fixed

  • Don't display image timestamp if no image is there
  • Allow for multiple img tags on a row
  • Switch from complex regex to easier DOMDocument search
  • Issue with integration tests and Monolog 2.7
  • Add GitHub Actions composer cacheq

[0.3.9] - 29 June 2022

Fixed

  • Normalize base URL as well
  • Change html_entity_decode into escaper for PHPCS

[0.3.8] - 29 June 2022

Fixed

  • Make sure to keep HTTPS URLs for media intact
  • Convert static files into static URLs properly

[0.3.7] - 29 June 2022

Fixed

  • Normalized URLs don't match anymore with media URL and static URL (WebP #122)

[0.3.6] - 27 June 2022

Fixed

  • Handle URLs starting without protocol (//) in a better way (#34)

[0.3.5] - 12 June 2022

Fixed

  • Strip query string from source image URL (@theuargb)

[0.3.4] - 7 June 2022

Fixed

  • Make sure non-existing sources don't throw exceptions

[0.3.3] - 2 June 2022

Fixed

  • Do not edit gallery JSON when module is disabled

[0.3.2] - 21 May 2022

Fixed

  • Fix URL-to-file conversion for URL-decoded URLs
  • Respect native lazy loading attribute #29 (@pointia)

[0.3.1] - 19 May 2022

Fixed

  • Set sane defaults for all configuration values
  • Check if extension is enabled for plugin #30 (@artbambou)

Added

  • Beautify console output

[0.3.0] - 4 May 2022

Fixed

  • Same WebP image for example.jpg and example.jpeg
  • Improve translating static file URLs into filenames
  • Add event observer to make sure blocks with non-zero TTL are parsed when FPC is enabled
  • Fix issues with Product Swatches

Added

  • Various unit tests
  • Live testing for better testing
  • Moved AJAX plugin for swatches from WebP extension to NextGenImages
  • New config option for target directory
  • New config option for adding an unique hash for target images
  • Implement hash when creating target images

[0.2.13] - 10 December 2021

Fixed

  • isNewerThan method is not reached when the converted image already exists (@peteracs)

[0.2.12] - 10 November 2021

Added

  • Allow file driver interface to be overwritten

[0.2.11] - 26 October 2021

Fixed

  • Make sure non-self-breaking sources don't break

[0.2.10] - 17 August 2021

Fixed

  • Prevent file check from reading whole file (performance issue)

[0.2.9] - 17 August 2021

Fixed

  • Fatal Error on swatches AJAX call

Removed

  • DummyConvertor with DI preference
  • UrlReplacer used only in CorrectImagesInAjaxResponse

[0.2.8] - 17 August 2021

Fixed

  • Wrap exceptions so they don't appear in frontend
  • Prevent non-existing files from throwing NotFoundException

[0.2.7] - 13 August 2021

Fixed

  • Be more helpful when non-existing image is used in convert command
  • Make sure UrlConvertor throws error properly (@Quazz)

[0.2.6] - 13 August 2021

Fixed

  • Exception was supplied Phrase instead of string

[0.2.5] - 12 August 2021

Fixed

  • Remove debugging info

[0.2.4] - 12 August 2021

Fixed

  • Make sure plugin ConvertAfterImageSave still respects original return value

Added

  • Additional debug options for CLI command
  • Support for media URL different from base URL (like CDNs)

[0.2.3] - 7 July 2021

Fixed

  • Add current store to all methods
  • Make sure ConvertorListing works even though no convertor is available
  • Hide all other fields if setting "Enabled" is set to 0
  • Make sure plugins are off when module is configured to be disabled

[0.2.2] - 29 June 2021

Fixed

  • Make sure CLI converts images with their absolute path
  • Only convert image URLs matching the Magento base URL [@tdgroot]

[0.2.1] - 9 March 2021

Fixed

  • Fix Dummy convertor to prevent compilation error

[0.2.0] - 9 March 2021

Added

  • New option to try to convert on saving
  • Add console command for converting images manually
  • Add command to test for URIs quickly
  • Update convertor to make second arg optional

[0.1.1] - 15 February 2021

Fixed

  • Fix composer version
  • Fix word "Logging" in config options

[0.1.0] - 15 February 2021

Added

  • Enhance debugger with logging option
  • Add logging with every exception

[0.0.6] - 7 January 2021

Fixed

  • Reimplement data-src (PR 51 from the Yireo_Webp2 module)

[0.0.5] - 3 December 2020

Fixed

  • Add dummy convertor with DI preference
  • Replace all WebP deps with NextGenImages deps

[0.0.4] - 2 December 2020

Fixed

  • Re-add dep with WebP2 in controller

[0.0.3] - 2 December 2020

Fixed

  • Remove deps with WebP2 module
  • Add missing Browser class

[0.0.2] - 30 November 2020

Added

  • Methods to added to ConvertorInterface

Removed

  • Remove duplicate DI.xml (and add docs for this)

[0.0.1] - 30 November 2020

Added

  • Initial release together with Yireo WebP2
Versions
Version Stability QA Status Compatibility Released
0.5.15 stable Pass Magento 2.4.7-2.4.8 Details 2025-10-22 11:21:53
0.5.14 stable Not tested Not yet tested Details 2025-07-24 07:36:08
0.5.13 stable Not tested Not yet tested Details 2025-04-23 11:24:00
0.5.12 stable Not tested Not yet tested Details 2025-02-19 12:51:50
0.5.11 stable Not tested Not yet tested Details 2025-02-11 08:21:47
0.5.10 stable Not tested Not yet tested Details 2024-12-11 09:17:15
0.5.9 stable Not tested Not yet tested Details 2024-12-04 18:32:23
0.5.8 stable Not tested Not yet tested Details 2024-10-24 12:31:45
0.5.7 stable Not tested Not yet tested Details 2024-08-26 07:29:57
0.5.6 stable Not tested Not yet tested Details 2024-08-23 14:51:36
0.5.5 stable Not tested Not yet tested Details 2024-08-23 09:45:12
0.5.3 stable Not tested Not yet tested Details 2024-05-22 14:28:55
0.5.2 stable Not tested Not yet tested Details 2024-04-04 13:16:31
0.5.1 stable Not tested Not yet tested Details 2024-02-27 13:46:44
0.5.0 stable Not tested Not yet tested Details 2023-09-22 10:38:45
0.4.1 stable Not tested Not yet tested Details 2023-08-14 11:40:07
0.4.0 stable Not tested Not yet tested Details 2023-03-16 19:11:37
0.3.18 stable Not tested Not yet tested Details 2023-03-05 14:10:12
0.3.17 stable Not tested Not yet tested Details 2023-03-05 12:32:49
0.3.16 stable Not tested Not yet tested Details 2023-03-01 15:48:38
0.3.15 stable Not tested Not yet tested Details 2023-02-28 13:28:11
0.3.14 stable Not tested Not yet tested Details 2023-02-27 16:04:45
0.3.13 stable Not tested Not yet tested Details 2023-02-27 11:39:21
0.3.12 stable Not tested Not yet tested Details 2023-01-10 13:47:18
0.3.11 stable Not tested Not yet tested Details 2022-10-24 11:07:46
0.3.10 stable Not tested Not yet tested Details 2022-07-03 18:35:15
0.3.9 stable Not tested Not yet tested Details 2022-06-29 12:54:29
0.3.8 stable Not tested Not yet tested Details 2022-06-29 10:25:55
0.3.7 stable Not tested Not yet tested Details 2022-06-29 10:13:16
0.3.6 stable Not tested Not yet tested Details 2022-06-27 13:45:48
0.3.5 stable Not tested Not yet tested Details 2022-06-12 07:58:31
0.3.4 stable Not tested Not yet tested Details 2022-06-07 17:45:14
0.3.3 stable Not tested Not yet tested Details 2022-06-02 10:20:47
0.3.2 stable Not tested Not yet tested Details 2022-05-21 07:58:07
0.3.1 stable Not tested Not yet tested Details 2022-05-19 06:27:08
0.3.0 stable Not tested Not yet tested Details 2022-05-04 15:20:28
0.2.13 stable Not tested Not yet tested Details 2021-12-11 09:19:55
0.2.12 stable Not tested Not yet tested Details 2021-11-10 15:45:19
0.2.11 stable Not tested Not yet tested Details 2021-10-26 16:16:45
0.2.10 stable Not tested Not yet tested Details 2021-09-23 13:29:58
0.2.9 stable Not tested Not yet tested Details 2021-09-15 12:05:56
0.2.8 stable Not tested Not yet tested Details 2021-08-17 11:57:25
0.2.7 stable Not tested Not yet tested Details 2021-08-13 15:53:17
0.2.6 stable Not tested Not yet tested Details 2021-08-13 09:26:37
0.2.5 stable Not tested Not yet tested Details 2021-08-12 13:31:55
0.2.4 stable Not tested Not yet tested Details 2021-08-12 13:29:31
0.2.3 stable Not tested Not yet tested Details 2021-07-07 07:17:11
0.2.2 stable Not tested Not yet tested Details 2021-06-29 10:57:08
0.2.1 stable Not tested Not yet tested Details 2021-03-09 19:16:02
0.2.0 stable Not tested Not yet tested Details 2021-03-09 16:44:10
0.1.2 stable Not tested Not yet tested Details 2021-03-09 06:58:14
0.1.1 stable Not tested Not yet tested Details 2021-02-15 12:39:03
0.0.7 stable Not tested Not yet tested Details 2021-02-15 12:37:27
0.0.6 stable Not tested Not yet tested Details 2021-01-07 18:16:50
0.0.5 stable Not tested Not yet tested Details 2020-12-03 07:45:08
0.0.4 stable Not tested Not yet tested Details 2020-12-03 06:14:24
0.0.3 stable Not tested Not yet tested Details 2020-12-02 06:57:39
0.0.2 stable Not tested Not yet tested Details 2020-12-01 08:55:46
0.0.1 stable Not tested Not yet tested Details 2020-11-30 15:08:34

Requires 14

Package Constraint
ext-dom *
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-catalog ^100.0|^101.0|^102.0|^103.0|^104.0
magento/module-config ^101.0
magento/module-configurable-product ^100.0
magento/module-page-cache ^100.0
magento/module-store ^100.0|^101.0
magento/module-swatches ^100.0
php >=7.4.0
psr/log ^1 || ^2 || ^3
yireo/magento2-csp-utilities ^1.0

Requires-dev 4

Package Constraint
bitexpert/phpstan-magento ^0.3.0
phpstan/phpstan ^0.12.32
phpunit/phpunit ^9.0|^10.0|^11.0
yireo/magento2-integration-test-helper @dev

Suggests 1

Package Reason
yireo/magento2-webp2 Support for WebP2 images

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 not tested

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 Warning 45 45 warnings (ruleset: Magento2) — 15 auto-fixable with phpcbf
PHPMD Warning 15 15 rule violations (UnusedFormalParameter:8, UnusedPrivateMethod:2, UnusedLocalVariable:1, DuplicatedArrayKey:1, EmptyCatchBlock: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. Cell → details modal.

PHPStan results by Magento and PHP version
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

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

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 Pass 0
Malware scan Pass 0
License
OSL-3.0
Homepage
https://www.yireo.com/software/magento-extensions/next-gen-images
Authors

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.