# yireo/magento2-next-gen-images

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

`composer require yireo/magento2-next-gen-images`

Canonical URL: https://packagento.com/yireo/magento2-next-gen-images

## At a glance

- **Vendor**: yireo (https://packagento.com/yireo.md)
- **Latest version**: 0.5.15 — released 2025-10-22
- **Pricing**: Free
- **Package type**: Magento 2 module
- **Status**: active, accepting new buyers

## Installation

Packagento is licence-gated, so even free packages need a licence on a project before Composer can resolve them.

1. **Sign in or create an account** at https://packagento.com/customer/account/.

2. **Add the package to your account.** Open https://packagento.com/yireo/magento2-next-gen-images and complete the free checkout. A licence is minted automatically.

3. **Create or pick a project, then activate the licence on it.**
   - Projects represent the Magento installs you deploy to. Manage them at https://packagento.com/projects/.
   - Activate the new licence on the project you'll deploy this package to. Activation is what generates the Composer credentials scoped to that project.

4. **Add the project credentials to your Magento codebase.**

   Grab the project's public + private key from https://packagento.com/projects/ (open the project, then its Credentials tab), and add them to `auth.json`:

   ```json
   {
     "http-basic": {
       "packagento.com": {
         "username": "ppk_live_...",
         "password": "psk_live_..."
       }
     }
   }
   ```

   Add the Packagento Composer repository to `composer.json`:

   ```json
   {
     "repositories": [
       { "type": "composer", "url": "https://packagento.com" }
     ]
   }
   ```

5. **Install and apply.**

   ```bash
   composer require yireo/magento2-next-gen-images:*
   bin/magento setup:upgrade
   bin/magento setup:di:compile
   bin/magento cache:flush
   ```

## What it does

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

## 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](https://github.com/yireo/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
<?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:

```php
$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](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

### [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

_(Changelog truncated for .md surface. Full history on https://packagento.com/yireo/magento2-next-gen-images.)_

## Recent Versions

| Version | Released |
|---|---|
| 0.5.15 | 2025-10-22 |
| 0.5.14 | 2025-07-24 |
| 0.5.13 | 2025-04-23 |
| 0.5.12 | 2025-02-19 |
| 0.5.11 | 2025-02-11 |
| 0.5.10 | 2024-12-11 |
| 0.5.9 | 2024-12-04 |
| 0.5.8 | 2024-10-24 |
| 0.5.7 | 2024-08-26 |
| 0.5.6 | 2024-08-23 |

Showing 10 of 59 versions. Full release history on https://packagento.com/yireo/magento2-next-gen-images.

## Dependencies

### Require

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

### Require (dev)

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

### Suggest

| Package | Constraint |
|---|---|
| yireo/magento2-webp2 | Support for WebP2 images |

## Quality

Latest release (0.5.15) passes the Packagento QA pipeline. Verdicts below are per-cell (Magento line × PHP version) for the matrixed tools, and run-once for the static / security tiers.


### Compatibility

Each Magento line is installed on its supported PHP versions, then the module is built (DI compile + static-content deploy). Cells show passed / failed / untested; staircase gaps render as `–`.

| 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. Never affect the Compatibility verdict — 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.

| 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 against a real Magento install. Re-runs per Magento + PHP version because resolvable symbols differ between releases.

| 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 per Magento + PHP cell. Test failures speak to the module's behaviour, not its compatibility with a line, so they're reported here separately.

#### Unit Tests

| 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

Dependency-advisory audit (composer audit) plus a source malware scan. A malware detection fails the version outright.

| Tool | Status | Findings | Summary |
|---|---|---|---|
| Composer audit | Pass | 0 |  |
| Malware scan | Pass | 0 |  |

## Licence and pricing

Free. A licence is still minted on checkout and bound to your project for Composer access — no payment step.

Refundable within 14 days of first purchase via https://packagento.com/account/refunds/.

## Install via Claude Code or any MCP client

The Packagento MCP server can run the licence + project + Composer steps above in one tool call:

```
purchase_and_install_packages(
  composer_names=["yireo/magento2-next-gen-images"],
  project_id="proj_xxx"
)
```

This handles cart, checkout, licence minting, project activation, and writes auth.json credentials. Connect a client with `claude mcp add packagento https://mcp.packagento.com`. Full setup at https://packagento.com/docs/mcp-setup.

## Vendor

yireo is a Magento 2 vendor on Packagento. See https://packagento.com/yireo.md for their full catalogue.

