Reputation: 8713
I have an extension using a Fluid template which looks like this:
<div class="bgimg" style="background-image: url({f:uri.image(src:'uploads/tx_slider/{homeslider1.bgimage}', treatIdAsReference:1, maxWidth:'1600')})"></div>
This works well - the background-image is referenced correctly - and the image is resized if it is too large. However my client started to upload images in PNG format, which resulted in large (>5MB) files in the website output.
I have not found any option to tell the Fluid image helper to convert the PNG image to JPG when processing. What can I do?
Upvotes: 1
Views: 971
Reputation: 423
as of TYPO3 10.3 there is a new fluid attribute named "fileExtension" for this.
<f:image fileExtension="jpg" image="{file}" />
You can read more about this feature here: https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/10.3/Feature-90416-SpecificTargetFileExtensionInImage-relatedViewHelpers.html
Upvotes: 2
Reputation: 8713
I have no answer on my question - but this is my workaround:
DELETE FROM sys_file_processedfile;
SELECT DISTINCT REPLACE(CONCAT('magick .', identifier, ' .', identifier, '.jpg'), 'user_upload/', 'fileadmin/user_upload') AS cmd FROM sys_file WHERE extension='png' AND size > 500000;
SELECT DISTINCT CONCAT('fart.exe "sqlbackup.sql" "', SUBSTRING_INDEX(identifier, '/', -1), '" "', SUBSTRING_INDEX(identifier, '/', -1), '.jpg"') AS cmd FROM sys_file WHERE extension='png' AND size > 500000;
Query 1: Delete Image Cache
Query 2: Create a batch command to convert all PNG images to JPG which are larger than 500kB. I executed this batch from the root of my Typo3 installation. ImageMagick must be installed.
Query 3: Create a batch command to replace all occurrences of those PNG files in the database. I created a backup of the DB and than I ran "fart.exe" on the backup file. Fart.exe is a fast and simple text replacement tool. After that I imported the backup, cleared the cache and Typo3 was using the much smaller JPG files (about 250kB compared to 5MB).
Upvotes: 0