Feature: #93981 - Specify default image conversion processing
See forge#93981
Description
Image processing in TYPO3 can now configure default and specific formats to use when images are rendered or converted in the frontend, for example in Fluid:
<f:image src="{asset.path}" width="200" />
<f:image src="fileadmin/someFile.jpg" width="200" />
<f:image image="{someExtbaseObject.someAsset}" width="200" />
Depending on the TYPO3 version, processed images were rendered with
.png (or earlier, .gif or .png) file extensions, as
long as the file parameter with a fixed output format was not
specified.
This default solution had two major drawbacks:
- The default file format was hardcoded and not configurable.
- Utilizing new file formats (like
webpandavif) required code changes.
This has now been changed with the new configuration option
$GLOBALS.
This variable defaults to:
$GLOBALS['TYPO3_CONF_VARS']['GFX']['imageFileConversionFormats'] = [
'jpg' => 'jpg',
'jpeg' => 'jpeg',
'gif' => 'gif',
'png' => 'png',
'svg' => 'svg',
'default' => 'png',
];
This means:
- When resizing or cropping an image with a file extension of
jpg,jpeg,gif,png, orsvg(and not setting a specificfiletarget format), those images will retain their respective file formats.Extension - Otherwise, the file format
pngis used.
Related configuration options that still apply:
$GLOBALSCurrent default:['TYPO3_ CONF_ VARS'] ['GFX'] ['imagefile_ ext'] gif,jpg,jpeg,tif,tiff,bmp,pcx,tga,png,pdf,ai,svg,webp,avif$GLOBALSCurrent default:['TYPO3_ CONF_ VARS'] ['SYS'] ['textfile_ ext'] txt,ts,typoscript,html,htm,css,tmpl,js,sql,xml,csv,xlf,yaml,yml$GLOBALSCurrent default:['TYPO3_ CONF_ VARS'] ['SYS'] ['mediafile_ ext'] gif,jpg,jpeg,bmp,png,webp,pdf,svg,ai,mp3,wav,mp4,ogg,flac,opus,webm,youtube,vimeo,avif
These still define, per installation, which files can be uploaded or used as images.
If a new format like heic becomes supported by the used graphics
engine (for example GraphicsMagick or ImageMagick), system maintainers can add
the file extension to
imagefile_. TYPO3 will then recognize this
format and convert it to the default target format (png by default) when
processing images.
If the format should also be available as a target format, add
'heic' => 'heic' to
$GLOBALS.
Otherwise, heic images can be selected, but processing will still produce
png.
If all image processing (resizing, thumbnails, PDF previews, etc.) should use
heic, set
'default' => 'heic' and remove other entries.
Currently, the option cannot be configured via
System > Settings > Configure options ... because it uses
an array syntax. It can be changed manually in settings.. GUI
support may be added in a future release.
The array notation allows defining a target (thumbnail) file extension for
each original file extension individually using the format
{original.
Example:
$GLOBALS['TYPO3_CONF_VARS']['GFX']['imageFileConversionFormats'] = [
'jpg' => 'jpg',
'svg' => 'svg',
'ai' => 'png',
'heic' => 'webp',
'default' => 'avif',
];
This configuration would produce the following behavior:
<f:image src="somefile.jpg" width="80">
-> renders an 80 px thumbnail from "somefile.jpg" to "somefile.jpg"
(rule: "jpg => jpg")
<f:image src="somefile.gif" width="80">
-> renders an 80 px thumbnail from "somefile.gif" to "somefile.avif"
(rule: "default => avif")
<f:image src="somefile.png" width="80">
-> renders an 80 px thumbnail from "somefile.png" to "somefile.avif"
(rule: "default => avif")
<f:image src="somefile.svg" width="80">
-> renders the original SVG at 80 px width
(rule: "svg => svg")
<f:image src="somefile.pdf" width="80">
-> renders an 80 px PDF thumbnail to "somefile.avif"
(rule: "default => avif")
<f:image src="somefile.heic" width="80">
-> renders an 80 px thumbnail from "somefile.heic" to "somefile.webp"
(rule: "heic => webp")
Impact
TYPO3 is now more future-proof regarding new image formats and allows modern file formats to be used by configuration.
Projects can now specify precisely how each format should be converted or which default format should be used for processed images.