Usage
This chapter shows practical examples for integrating responsive images into your Fluid templates and for operating the command-line tools that ship with the extension.
Register the namespace
Add the ViewHelper namespace at the top of your Fluid template or register it globally:
{namespace nr=Netresearch\NrImageOptimize\ViewHelpers}
Basic responsive image
<nr:sourceSet file="{image}"
width="1200"
height="800"
sizes="(max-width: 768px) 100vw, 50vw"
/>
Quality is not configurable per call: the ViewHelper always
emits its default quality of 75 into the generated
/processed/... URL.
Responsive width-based srcset
Enable width-based srcset generation with a sizes
attribute for improved responsive image handling. This is
opt-in per usage.
<nr:sourceSet
path="{f:uri.image(
image: image,
maxWidth: size,
cropVariant: 'default'
)}"
width="{size}"
height="{size * ratio}"
alt="{image.properties.alternative}"
lazyload="1"
mode="fit"
responsiveSrcset="1"
/>
Custom width variants
<nr:sourceSet
path="{f:uri.image(
image: image,
maxWidth: size,
cropVariant: 'default'
)}"
width="{size}"
height="{size * ratio}"
responsiveSrcset="1"
widthVariants="320,640,1024,1920,2560"
sizes="(max-width: 640px) 100vw,
(max-width: 1024px) 75vw, 50vw"
/>
Output comparison
Note
The examples on this page leave out the ?sig=<signature> query
parameter that every rendered /processed/ URL carries (see
Signed variant URLs).
Legacy mode (responsive or not set):
<img src="/processed/fileadmin/image.w625h250m1q75.jpg"
srcset="/processed/fileadmin/image.w1250h500m1q75.jpg x2"
width="625"
height="250"
loading="lazy">
Responsive mode (responsive):
<img src="/processed/fileadmin/image.w1250h1250m1q75.png"
srcset="/processed/fileadmin/image.w480h480m1q75.png 480w,
/processed/fileadmin/image.w576h576m1q75.png 576w,
/processed/fileadmin/image.w640h640m1q75.png 640w,
/processed/fileadmin/image.w768h768m1q75.png 768w,
/processed/fileadmin/image.w992h992m1q75.png 992w,
/processed/fileadmin/image.w1200h1200m1q75.png 1200w,
/processed/fileadmin/image.w1800h1800m1q75.png 1800w"
sizes="auto, (min-width: 992px) 991px, 100vw"
width="991"
loading="lazy"
alt="Image">
Public images only: absolute URLs are passed through
New in version 2.2.4
Absolute URLs, data: URIs, and URLs with a query string are
passed through unchanged and rendered as a plain <img> tag.
The /processed/ endpoint is designed for public files only.
It resolves the given path below the public web root and writes the
generated variants as static files into public/,
where the web server delivers them directly — without any access
check.
Files in non-public FAL storages (is_) can therefore
not be processed.
Changed in version 2.6.1
The processor refuses source files that lie inside the base path
of a non-public Local storage -- also when that directory sits
below the public web root and when a variant of the file is
already on disk -- with HTTP 404, or with HTTP 400 when the file
resolves outside every allowed root (non-public storages are not
allowed roots). Remove variants of such files
that earlier versions wrote below public/ (see
Clear processed images): the web server delivers files there
without asking TYPO3.
Extensions such as
fal_securedownload
resolve such files to tokenized eID URLs
(/index.) whose delivery runs through TYPO3
and performs a permission check on every request.
The ViewHelper detects absolute URLs (http://, https://,
//), data: URIs, and URLs containing a query string and
passes them through unchanged, rendering a plain <img> tag with
the URL as src:
<picture>
<img src="https://example.org/index.php?eID=dumpFile&t=f&f=42&fal_token=..."
width="400"
height="300"
alt="Protected image" />
</picture>
Important
Trade-off for passed-through URLs
- No
srcset/sizesattributes and no per-breakpoint<source>elements are generated — the browser always loads the image in its original dimensions. - No WebP/AVIF variants and no quality optimization are applied.
- In return, the access control of the generating extension (e.g. fal_securedownload) stays fully intact, because the URL — including its access token — is emitted unchanged.
If you need optimized variants of images in protected storages,
generate them with TYPO3's own image processing (for example
f: or the Image). Processed files are then
created inside the protected storage's processing folder and are
delivered through the same secure-download mechanism, keeping the
permission check intact.
Fetch priority for Core Web Vitals
Use the fetchpriority attribute to hint the browser
about resource prioritization, improving Largest Contentful
Paint (LCP) scores:
<nr:sourceSet file="{heroImage}"
width="1920"
height="1080"
fetchpriority="high"
/>
Skip WebP or AVIF generation
New in version 2.7.0
The skip and skip ViewHelper arguments.
By default the first request for a variant writes the source
format plus a .webp and an .avif sidecar. AVIF encoding
is the most expensive of the three. Set skip and/or
skip to leave a format out for one ViewHelper call; the
flag is added to every URL the call renders:
<nr:sourceSet path="{f:uri.image(image: image)}"
width="1200"
height="800"
skipAvif="1"
/>
With both flags set, each variant is written in its source format only.
Note
The flags only control generation, and they are not part of the variant's file name, so templates that render the same image at the same size share one set of files. Whichever request creates the variant first decides which sidecars exist:
- A sidecar already written by a request without the flag is still served.
- A variant first created with the flag gets no such sidecar later, not even for a template without the flag, until the processed images are cleared (see Clear processed images).
The flags are part of the URL signature, so only a template can set them; a flag added to a rendered URL is refused (see Signed variant URLs).
To turn a format off for the whole installation, use the extension settings instead.
Command-line tools
Both commands read the FAL index directly and process eligible
image files (image/, image/, image/) on
online storages. Per-file storage permission evaluation is
temporarily disabled and restored in a finally block so
long-running CLI runs don't leak state across iterations or
require a BE user context.
Bulk optimize images
The nr: command compresses every eligible
PNG, GIF, and JPEG file across all storages (or a restricted
subset) using the installed optimizer binaries. The original
file is replaced in place only when the tool produces a
smaller result.
vendor/bin/typo3 nr:image:optimize --dry-run
vendor/bin/typo3 nr:image:optimize \
--storages=1 \
--jpeg-quality=85 \
--strip-metadata
Options:
--dry- run - Only analyze; do not modify files.
--storages - Restrict to specific storage UIDs. Accepts repeated occurrences or a comma-separated list.
--jpeg- quality - Lossy JPEG quality 0--100. Omit for lossless JPEG optimization.
--strip- metadata - Remove EXIF and comments when the tool supports it.
Analyze optimization potential
The nr: command estimates how much disk
space could be saved by running nr: or by
downscaling oversized originals. It is purely heuristic --
no external binaries are invoked, so it runs quickly even on
large installations.
vendor/bin/typo3 nr:image:analyze --storages=1
Options:
--storages - Restrict to specific storage UIDs.
--/max- width --max- height - Target display box (default 2560 x 1440). Images larger than this box are assumed to be downscaled and the estimate factors in the area reduction.
--min- size - Skip files smaller than this many bytes (default 512000). Prevents noise from already-tiny images.