figure - Twig Function
This function allows you to create a processed (resized and/or cropped) image directly in your Twig template via
Contao’s Image Studio. It will return a Figure instance which you can then render in
your template - or pass to a pre-existing block of a component, or a pre-existing template. If the resource is not found,
it will return null instead.
The function takes 3 arguments: the source image, the size configuration and additional options. The
following example creates a Figure object from a hardcoded path and size and then renders it using the _figure
component:
You can also set more options for the FigureBuilder, like setting additional meta data, a lightbox identifier, an
image size for the full size image, etc.:
See the dedicated templates section for more examples.
You can also extract the resized image by accessing the src of the resulting <img>:
If required you can also access the path to the original file. However, keep in mind that this path will not be encoded.
Arguments
from: Can be aFilesModel, aFilesystemItem, anImageInterface, atl_filesUUID/ID/path or a file system path.size: A picture size configuration or reference or size array.configuration: Additional configuration for theFigureBuilder.