Image ViewHelper <f:image>
Resizes a given image (if required) and renders the respective img tag.
Note that image operations (cropping, scaling, converting) on non-FAL files (i.e. extension resources) may be changed in future TYPO3 versions, since those operations are coupled with FAL metadata. Each non-FAL image operation creates a "fake" FAL record, which may lead to problems.
External URLs are not processed. Only a given width and height will be set on the tag.
Examples
Default
<f:image src="EXT:myext/Resources/Public/typo3_logo.png" alt="alt text" />
Output in frontend:
<img alt="alt text" src="typo3conf/ext/myext/Resources/Public/typo3_logo.png" width="396" height="375" />
or in backend:
<img alt="alt text" src="../typo3conf/ext/viewhelpertest/Resources/Public/typo3_logo.png" width="396" height="375" />
Image Object
<f:image image="{imageObject}" />
Output:
<img alt="alt set in image record" src="fileadmin/_processed_/323223424.png" width="396" height="375" />
Inline notation
{f:image(src: 'EXT:viewhelpertest/Resources/Public/typo3_logo.png', alt: 'alt text', minWidth: 30, maxWidth: 40)}
Output:
<img alt="alt text" src="../typo3temp/assets/images/f13d79a526.png" width="40" height="38" />
Depending on your TYPO3s encryption key.
Other resource type (e.g. PDF)
<f:image src="fileadmin/user_upload/example.pdf" alt="foo" />
If your graphics processing library is set up correctly then it will output a thumbnail of the first page of your PDF document:
<img src="fileadmin/_processed_/1/2/csm_example_aabbcc112233.gif" width="200" height="284" alt="foo">
Non-existent image
<f:image src="NonExistingImage.png" alt="foo" />
Could not get image resource for "NonExistingImage.png".
Base64 attribute
When the base64 argument is set to true, the resulting image tag contains the source of the image in a base64 encoded form.
<f:image base64="true"
src="EXT:backend/Resources/Public/Images/typo3_logo_orange.svg"
class="pr-2"
/>
Will result in the according HTML tag providing the image encoded in base64.
<img class="pr-2"
src="data:image/svg+xml;base64,PHN2...cuODQ4LTYuNzU3Ii8+Cjwvc3ZnPgo="
alt=""
>
This can be particularly useful inside Fluid
or to prevent unneeded HTTP calls.
Source code
Go to the source code of this ViewHelper: ImageViewHelper.php (GitHub).
Arguments
Allows arbitrary arguments
This ViewHelper allows you to pass arbitrary arguments not defined below directly
to the HTML tag created. This includes custom
data-
arguments.
The following arguments are available for the image ViewHelper:
absolute
-
- Type
- bool
- Default
- false
Force absolute URL
additionalAttributes
-
- Type
- array
Additional tag attributes. They will be added directly to the resulting HTML tag.
aria
-
- Type
- array
Additional aria-* attributes. They will each be added with a "aria-" prefix.
base64
-
- Type
- bool
- Default
- false
Adds the image data base64-encoded inline to the image‘s "src" attribute. Useful for FluidEmail templates.
crop
-
- Type
- string|bool|array
overrule cropping of image (setting to FALSE disables the cropping set in FileReference)
cropVariant
-
- Type
- string
- Default
- 'default'
select a cropping variant, in case multiple croppings have been specified or stored in FileReference
data
-
- Type
- array
Additional data-* attributes. They will each be added with a "data-" prefix.
fileExtension
-
- Type
- string
Custom file extension to use
height
-
- Type
- string
height of the image. This can be a numeric value representing the fixed height of the image in pixels. But you can also perform simple calculations by adding "m" or "c" to the value. See imgResource.width for possible options.
image
-
- Type
- object
a FAL object (\TYPO3\CMS\Core\Resource\File or \TYPO3\CMS\Core\Resource\FileReference)
maxHeight
-
- Type
- int
maximum height of the image
maxWidth
-
- Type
- int
maximum width of the image
minHeight
-
- Type
- int
minimum height of the image
minWidth
-
- Type
- int
minimum width of the image
src
-
- Type
- string
- Default
- ''
a path to a file, a combined FAL identifier or an uid (int). If $treatIdAsReference is set, the integer is considered the uid of the sys_file_reference record. If you already got a FAL object, consider using the $image parameter instead
treatIdAsReference
-
- Type
- bool
- Default
- false
given src argument is a sys_file_reference record
width
-
- Type
- string
width of the image. This can be a numeric value representing the fixed width of the image in pixels. But you can also perform simple calculations by adding "m" or "c" to the value. See imgResource.width for possible options.