.. |release| image:: https://img.shields.io/github/v/release/netresearch/t3x-nr-image-optimize?sort=semver
:target: https://github.com/netresearch/t3x-nr-image-optimize/releases/latest
.. |license| image:: https://img.shields.io/github/license/netresearch/t3x-nr-image-optimize
:target: https://github.com/netresearch/t3x-nr-image-optimize/blob/main/LICENSE
.. |ci| image:: https://github.com/netresearch/t3x-nr-image-optimize/actions/workflows/ci.yml/badge.svg
.. |php| image:: https://img.shields.io/badge/PHP-8.2%20|%208.3%20|%208.4-blue.svg
.. |typo3| image:: https://img.shields.io/badge/TYPO3-13.4-orange.svg
|php| |typo3| |license| |ci| |release|
.. _nr_image_optimize:
=====================================
๐ TYPO3 Extension: nr_image_optimize
=====================================
The ``nr_image_optimize`` extension is an advanced TYPO3 extension for image optimization. It provides lazy image processing, modern formats, responsive images, and performance optimizations.
๐จ Features
============
- ๐ **Lazy Image Processing**: Images are processed only when requested.
- ๐จ **Modern Format Support**: WebP and AVIF with automatic fallback.
- ๐ฑ **Responsive Images**: Built-in ViewHelper for srcset generation.
- โก **Performance Optimized**: Middleware-based processing for efficiency.
- ๐ง **Intervention Image**: Powered by the Intervention Image library.
- ๐ **Core Web Vitals**: Improves LCP and overall page performance.
๐ ๏ธ Requirements
================
- PHP 8.2, 8.3, or 8.4
- TYPO3 13.4
- Intervention Image library (installed via Composer automatically)
๐ Recommended Extensions
========================
- `https://github.com/christophlehmann/imageoptimizer`
๐พ Installation
================
Via Composer (recommended)
------------------------
.. code-block:: bash
composer require netresearch/nr-image-optimize
Manual Installation
------------------
1. Download the extension from the TYPO3 Extension Repository
2. Upload to ``typo3conf/ext/``
3. Activate the extension in the Extension Manager
โ๏ธ Configuration
================
The extension works out of the box with sensible defaults. Images are automatically optimized when accessed via the ``/processed/`` path.
ViewHelper Usage
----------------
.. code-block:: html
{namespace nr=Netresearch\NrImageOptimize\ViewHelpers}
Supported Parameters
---------------------
- ``file``: Image file resource
- ``width``: Target width in pixels
- ``height``: Target height in pixels
- ``quality``: JPEG/WebP quality (1-100)
- ``sizes``: Responsive sizes attribute
- ``format``: Output format (auto, webp, avif, jpg, png)
๐ Source Set Configuration
---------------------------
Different source sets can be defined for each media breakpoint via the ``set`` attribute:
.. code-block:: html
๐ผ๏ธ Render Modes
----------------
Two render modes are available for the ``SourceSetViewHelper``:
- **cover**: Default mode, resizes images to fully cover the provided width and height.
- **fit**: Resizes images so they fit within the provided width and height.
.. code-block:: html
๐ท Responsive width-based srcset
================================
The extension provides a responsive, width-based ``srcset`` generation with a ``sizes`` attribute
for improved responsive image handling. This feature is optional and can be enabled per usage.
New Parameters
--------------
``responsiveSrcset``
- Type: ``bool``
- Default: ``false``
- Description: Enable width-based responsive ``srcset`` generation instead of density-based (``x2``) ``srcset``.
``widthVariants``
- Type: ``string|array``
- Default: ``'480, 576, 640, 768, 992, 1200, 1800'``
- Description: Width variants for responsive ``srcset`` (comma-separated string or array).
``sizes``
- Type: ``string``
- Default: ``(max-width: 576px) 100vw, (max-width: 768px) 50vw, (max-width: 992px) 33vw, (max-width: 1200px) 25vw, 1250px``
- Description: ``sizes`` attribute for responsive images.
``fetchpriority``
- Type: ``string``
- Allowed values: ``high``, ``low``, ``auto``
- Default: ``''`` (omitted)
- Description: Adds the native HTML attribute ``fetchpriority`` to the generated ``
`` tag to hint the browser about resource prioritization. Any other value will be ignored.
Usage Examples
--------------
Enable responsive srcset with default values:
.. code-block:: html
Custom width variants:
.. code-block:: html
Custom sizes attribute:
.. code-block:: html
Output Comparison
-----------------
Legacy mode (``responsiveSrcset=false`` or not set):
.. code-block:: html
Responsive mode (``responsiveSrcset=true``):
.. code-block:: html
Backward Compatibility
----------------------
- By default, ``responsiveSrcset`` is set to ``false``, maintaining the existing 2x density-based ``srcset`` behavior.
- All existing templates will continue to work without modifications.
- To enable the new responsive ``srcset``, explicitly set ``responsiveSrcset="1"`` in your templates.
Lazy Loading
------------
- Both modes support lazy loading with native ``loading="lazy"`` attribute.
- When using JS-based lazy loading (``class="lazyload"``), the ``data-srcset`` attribute is added automatically.
๐งช Development & Testing
========================
Unit tests ensure functionality and code quality.
.. code-block:: bash
# Run all tests
composer ci:test
# Run specific tests
composer ci:test:php:cgl # Code style
composer ci:test:php:lint # PHP syntax
composer ci:test:php:phpstan # Static analysis
composer ci:test:php:unit # PHPUnit tests
composer ci:test:php:rector # Code quality
๐๏ธ Architecture
================
The extension uses a middleware approach for image processing:
1. **ProcessingMiddleware**: Intercepts requests to ``/processed/`` paths
2. **Processor**: Handles image optimization and format conversion
3. **SourceSetViewHelper**: Generates responsive image markup
โก Performance Considerations
=============================
- Images are processed only once and cached
- Supports native browser lazy loading
- Automatic format negotiation based on Accept headers
- Optimized for CDN delivery
๐ License
===========
GPL-3.0-or-later. See `LICENSE file `_ for details.
๐ Support
==========
For issues and feature requests, please use the `GitHub issue tracker `_.
๐ Credits
===========
Developed by `Netresearch DTT GmbH `_