Developer reference
Architecture
The extension has three entry points that share the same
ImageOptimizer service where applicable:
- ProcessingMiddleware intercepts frontend requests
matching the
/processed/path and delegates to Processor, which handles image optimization, format conversion, and caching. - OptimizeOnUploadListener reacts to PSR-14 file events
(
AfterFileAddedEventandAfterFileReplacedEvent) and delegates to ImageOptimizer for in-place lossless compression viaoptipng/gifsicle/jpegoptim. - OptimizeImagesCommand and AnalyzeImagesCommand iterate the FAL index from the CLI, extending AbstractImageCommand for shared iteration and option parsing. See Usage.
SourceSetViewHelper generates responsive <img> markup
in Fluid templates. MaintenanceController provides the
backend module for statistics and cleanup.
Directory structure
-
-
-
AbstractImageCommand.php
-
AnalyzeImagesCommand.php
-
OptimizeImagesCommand.php
-
-
-
MaintenanceController.php
-
-
-
OptimizeOnUploadListener.php
-
-
-
ProcessingMiddleware.php
-
-
-
ImageOptimizer.php
-
SystemRequirementsService.php
-
-
Processor.php
-
-
SourceSetViewHelper.php
-
-
-
-
-
Modules.php
-
-
Icons.php
-
RequestMiddlewares.php
-
Services.yaml
-
Processing middleware
- class ProcessingMiddleware
-
- Fully qualified name
-
\Netresearch\
Nr Image Optimize\ Middleware\ Processing Middleware
Frontend middleware registered before
typo3/cms-frontend/site. Intercepts requests whose path starts with/processed/and delegates image processing to the Processor class.
Processor
- class Processor
-
- Fully qualified name
-
\Netresearch\
Nr Image Optimize\ Processor
Core image processing engine. Parses the requested URL to extract dimensions, quality, mode, and format parameters. Uses the Intervention Image library for actual image manipulation. Processed images are cached on disk to avoid repeated processing.
SourceSetViewHelper
ImageOptimizer
- class ImageOptimizer
-
- Fully qualified name
-
\Netresearch\
Nr Image Optimize\ Service\ Image Optimizer
Shared service that shells out to
optipng,gifsicle, orjpegoptim(whichever is resolvable on the$PATH, or via theOPTIPNG_BIN/GIFSICLE_BIN/JPEGOPTIM_BINenvironment variables) viaproc_openwith argument arrays. Used by both OptimizeOnUploadListener and OptimizeImagesCommand. A missing binary degrades gracefully -- that format is simply skipped.
OptimizeOnUploadListener
- class OptimizeOnUploadListener
-
- Fully qualified name
-
\Netresearch\
Nr Image Optimize\ Event Listener\ Optimize On Upload Listener
PSR-14 listener for
AfterFileAddedEventandAfterFileReplacedEvent. Compresses newly uploaded/replaced files in place via ImageOptimizer, guarded against re-entrancy by storage UID + file identifier.
Console commands
- class AbstractImageCommand
-
- Fully qualified name
-
\Netresearch\
Nr Image Optimize\ Command\ Abstract Image Command
Shared template method for both commands below: storage UID parsing, FAL index iteration, and progress rendering.
- class OptimizeImagesCommand
-
- Fully qualified name
-
\Netresearch\
Nr Image Optimize\ Command\ Optimize Images Command
Backs
nr:image:optimize. See Usage.
- class AnalyzeImagesCommand
-
- Fully qualified name
-
\Netresearch\
Nr Image Optimize\ Command\ Analyze Images Command
Backs
nr:image:analyze. See Usage.
Testing
composer ci:test
Individual test commands:
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