b13 / picture
Improved TYPO3 image ViewHelper creating picture elements with support for sizes, sources, additional image formats, etc.
Installs: 131 501
Dependents: 1
Suggesters: 0
Security: 0
Stars: 18
Watchers: 13
Forks: 7
Open Issues: 2
Type:typo3-cms-extension
Requires
- typo3/cms-fluid: ^11.5 || ^12.4 || ^13.1
Requires (Dev)
- saschaegerer/phpstan-typo3: ^1.8
- typo3/cms-fluid: ^11.5 || ^12.4 || ^13.1
- typo3/coding-standards: ^0.5.5
- typo3/tailor: ^1.1
- typo3/testing-framework: ^7.0 || ^8.0
- dev-master
- 3.0.2
- 3.0.1
- 3.0.0
- 2.0.4
- 2.0.3
- 2.0.2
- 2.0.1
- 2.0.0
- 1.3.2
- 1.3.1
- 1.3.0
- 1.2.3
- 1.2.2
- 1.2.0
- 1.1.0
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0.0
- v0.1.1
- v0.1.0
- dev-task/gitattributes
- dev-bugfix/sources-without-width
- dev-davidsteeb-patch-4
- dev-davidsteeb-patch-3
- dev-update-documentation
- dev-render-picture-tag-only-if-needed
- dev-feature-only-webp
- dev-+42-svg-lazyloading
- dev-issue-53
- dev-test-36
- dev-davidsteeb-patch-2
- dev-davidsteeb-patch-1
- dev-patch-2
- dev-alternative-src-for-sources
- dev-phpunit
This package is auto-updated.
Last update: 2024-11-20 16:23:48 UTC
README
b13 Image View Helper
What it does
The b13 image view helper is a massive extension of the regular Fluid image ViewHelper. Basically it processes images and renders a single src element or a picture element depending on the specified configuration.
Installation
Install the extension using composer: composer req b13/picture
.
Include the TypoScript within your main template:
@import 'EXT:picture/Configuration/TypoScript/setup.typoscript'
Use Fluid Namespace B13\Picture
Use a proper configured Fluid template adding the namespace when using this ViewHelper:
<html
xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"
xmlns:i="http://typo3.org/ns/B13/Picture/ViewHelpers"
data-namespace-typo3-fluid="true"
>
TypoScript setup
See EXT:picture/Configuration/TypoScript/setup.typoscript
for possible configuration options (key: plugin.tx_picture
):
Attributes
All from f:image
Our image ViewHelper mimics the Fluid Image ViewHelper, so it has all the same attributes, including:
width
andheight
, includingc
option for crop scalingmaxWidth
for proportional scaling, without upscalingfileExtension
to set a file extension (to force webp for example)alt
andtitle
cropVariant
loading
to enable browser native lazy loading by default.
useRetina
If useRetina is set and not further specified in TypoScript setup, the corresponding img
tag's or source
tag’s
attribute srcset
is extended by a 2x retina version of the image.
addWebp
Adds rendering of additional images in webp format. If it is specified without a given sources attribute, it renders a
picture tag instead of a single img tag in order to maintain a browser fallback. If it is specified together with
sources
it adds an additional source
tag above any source
tag rendered by a given sources
element.
This attribute is ignored if onlyWebp
option is active.
onlyWebp
Enable only images in webp format and for all size variants.
Enabling this option disables addWebp
setting.
lossless
Enable lossless compression for webp images. If you find your webp images lacking in quality compared to jpg/png images, enable this option to overwrite default settings for ImageMagick/GraphicsMagick.
variants and sizes
Adds multiple variants of an image with different image sizes, optionally add a sizes-attribute to image tags:
variants="400, 600, 800, 1000" sizes="(min-width: 600px) 400px, 100vw"
This can also be part of the sources
-Array (see below).
sources
Sources must be notated as array. For each element given a source tag is rendered. It accepts the same attributes as the fluid image view helper. The source tags are rendered in the same ordering as specified in the array. If you do not specify additional TypoScript settings, any key can be used.
sources="{
0: {
width: '300c', height: '300c', media: 'min-width: 1000px', cropVariant: 'desktop', variants: '400, 600, 800', sizes: '100vw'
},
1: {
width: '250c', height: '250c', media: 'min-width: 600px', src: alternativefile.uid, treatIdAsReference: 1
},
2: {
width: '200c', height: '200c', media: 'min-width: 300px', cropVariant: 'teaser'
}
}"
pictureClass
Add a CSS class used for the picture
element (if rendered using <picture>
).
TypoScript Settings
In general
The following attributes can also be set in TypoScript as defaults for your whole site: addWebp
, useRetina
.
A default setting can be overridden for each usage of the ViewHelper by setting the corresponding attribute.
retina
The retina
option enables an extension of the default behaviour of the useRetina
attribute. If retina
is set, an
array should be specified with the multiplier for the image size as key, and the multiplier value output in the
corresponding tag.
retina {
2 = 2x
3 = 3x
}
breakpoints
With the array breakpoints
you can use those settings by using keys in your Fluid template (instead of adding media
queries for every key in your sources
array). It simply adds a media query for min-width.
breakpoints {
sm = 640
md = 1024
lg = 1280
}
Test rendering for demonstration purposes
You can include a test configuration to see the ViewHelper in your test instance frontend in action:
@import 'EXT:picture/Configuration/TypoScript/test.typoscript'
This configuration enables frontend rendering of the test file with lots of different rendering examples using the
page type 1573387706874
.
https://your.local.test.environment/?type=1573387706874
will render a page with different options to showcase code examples. This is intended for demonstration and testing purposes, not meant for your production environment.
Credits
This extension was created by Andreas Hämmerl and David Steeb in 2019 for b13 GmbH, Stuttgart.
Find more TYPO3 extensions we have developed that help us deliver value in client projects. As part of the way we work, we focus on testing and best practices ensuring long-term performance, reliability, and results in all our code.