yireo / magento2-next-gen-images
Magento 2 module to add NextGen images support to the Magento frontend
Package info
github.com/yireo/Yireo_NextGenImages
Type:magento2-module
pkg:composer/yireo/magento2-next-gen-images
Requires
- php: >=8.2 <8.6
- 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-checkout: ^100.0
- magento/module-config: ^101.0
- magento/module-configurable-product: ^100.0
- magento/module-page-cache: ^100.0
- magento/module-remote-storage: ^100.4
- magento/module-store: ^100.0|^101.0
- magento/module-swatches: ^100.0
- psr/log: ^1 || ^2 || ^3
Requires (Dev)
- ext-json: *
- bitexpert/phpstan-magento: ^0.42
- loki/magento2-functional-tests: @dev
- magento/module-media-storage: ^100.0
- phpstan/phpstan: ^2.0
- phpunit/phpunit: ^9.0|^10.0|^11.0
- yireo/magento2-integration-test-helper: ~0.0
Suggests
- yireo/magento2-webp2: Support for WebP2 images
Provides
None
Conflicts
None
Replaces
None
- dev-master
- 0.6.0
- 0.5.18
- 0.5.17
- 0.5.16
- 0.5.15
- 0.5.14
- 0.5.13
- 0.5.12
- 0.5.11
- 0.5.10
- 0.5.9
- 0.5.8
- 0.5.7
- 0.5.6
- 0.5.5
- 0.5.3
- 0.5.2
- 0.5.1
- 0.5.0
- 0.4.1
- 0.4.0
- 0.3.18
- 0.3.17
- 0.3.16
- 0.3.15
- 0.3.14
- 0.3.13
- 0.3.12
- 0.3.11
- 0.3.10
- 0.3.9
- 0.3.8
- 0.3.7
- 0.3.6
- 0.3.5
- 0.3.4
- 0.3.3
- 0.3.2
- 0.3.1
- 0.3.0
- 0.2.13
- 0.2.12
- 0.2.11
- 0.2.10
- 0.2.9
- 0.2.8
- 0.2.7
- 0.2.6
- 0.2.5
- 0.2.4
- 0.2.3
- 0.2.2
- 0.2.1
- 0.2.0
- 0.1.2
- 0.1.1
- 0.0.7
- 0.0.6
- 0.0.5
- 0.0.4
- 0.0.3
- 0.0.2
- 0.0.1
- dev-fix/security-hardening
- dev-fix/swatch-webp-images
- dev-feature/remote-storage-support-tests
- dev-pr-93
This package is auto-updated.
Last update: 2026-12-02 19:31:22 UTC
README
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.
Are PageBuilder background images (including mobile images) converted?
Yes, as long as the setting Convert CSS backgrounds (yireo_nextgenimages/settings/convert_css_backgrounds) is enabled. This setting is disabled by default. PageBuilder renders the desktop and mobile background images of rows, banners and sliders as background-image: url(...) in a <style> block, using a generated class .background-image-<id>. Both rules get an additional image-set() declaration (see below), so browsers keep using the original image when they don't support the converted format.
Can I prevent a specific image from being converted into a <picture> element?
Yes, add the attribute data-nextgenimages-skip to the image HTML:
<img src="/media/foo.jpg" alt="Foo" data-nextgenimages-skip>
To skip an entire page, add the XML layout handle nextgenimages_skip (or webp_skip) to it, for example with <update handle="nextgenimages_skip"/>. Image HTML inside a <script> (like var html = '<img src="...">';) or a <textarea> is never converted.
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);
Can next-gen images be generated together with the resized catalog images?
Yes. Enable the setting Convert images on save (yireo_nextgenimages/settings/convert_on_save, disabled by default). Each time Magento saves an image through Magento\Framework\Image::save(), the saved JPG or PNG is converted as well. This includes bin/magento catalog:images:resize and the resizing of product images after uploading them in the Admin Panel.
This is useful after flushing the catalog image cache while the Full Page Cache is still warm: The cached pages keep pointing to the original images, so no next-gen images are generated by visitors until those pages expire. To recover, run the following with the setting enabled:
bin/magento catalog:images:resize bin/magento cache:clean full_page
Note that this makes the resizing considerably slower, because every resized image is converted too.
Are CSS background images supported?
Partially. When the experimental setting Convert CSS backgrounds is enabled, a background or background-image declaration in an inline style attribute with a single local JPG or PNG image gets an additional image-set() declaration:
<div style="background-image: url(/media/foo.jpg); background-image: image-set(url('/media/foo.jpg.webp') type('image/webp'), url('/media/foo.jpg') type('image/jpeg'));"></div>
Browsers without image-set() support ignore the second declaration and keep using the original image. CSS files, <style> elements (except the PageBuilder background rules), scripts, Alpine :style bindings and multiple backgrounds are not converted.
How are the next-gen images named?
With the setting Add image hash disabled (default), the next-gen image keeps the full source filename and adds the new extension: foo.jpg becomes foo.jpg.webp and foo.png becomes foo.png.webp. With the setting enabled, the source extension is replaced by a hash of the source path: foo-<crc32>.webp.
Up to version 0.5.18, a hashless target name dropped the source extension (foo.webp), so foo.jpg and foo.png in the same folder overwrote each other's next-gen image. After upgrading, images are converted once more under the new name. The old foo.webp files are no longer used and can be removed. If you have webserver rules that map foo.jpg to foo.webp yourself, update them to foo.jpg.webp.
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