How to selectively remove processed image files in TYPO3
TL;DR: TYPO3 has no core solution to remove processed image files based on given constraints. My new extension
Processed Images Cleaner fills this gap and adds
a console command that deletes processed files selectively by storage, folder, file or processing configuration instead
of wiping the whole _processed_ folder at once.
The problem
On small TYPO3 websites with only a few images, cleaning up processed image files is no problem. You can simply delete
all files in the _processed_ folder (and truncate the sys_file_processedfile table) - which can also be achieved
via the Install Tool using the “Remove Temporary Assets” maintenance action. The next time a page is
requested, TYPO3 transparently regenerates the required processed files. On a website with just a handful of images,
this regeneration does not take very long, so nobody will notice.
I usually work in much bigger TYPO3 projects though, where you can not just delete all processed image files. In these projects, the files in FAL often have hundreds of GB of data with thousands of images, each rendered in different image sizes and crop variants. If you delete all processed image files at once, TYPO3 has to re-render every used image size and crop variant on the fly. This puts a huge load on the server and may end up in the webserver not responding anymore, because it is busy processing images instead of delivering pages.
So in the real world, you often only want to remove some processed image files - for example the processed files of a single folder, or all processed image files that were generated with a specific width or crop variant (e.g. after you changed the image handling configuration in a project). Unfortunately, TYPO3 has no core solution to individually remove processed files based on such constraints.
The extension
To fill this gap, I created the TYPO3 extension
Processed Images Cleaner. It provides a single,
Symfony console command that lets you remove processed image files selectively, based on given
constraints. The processed files are removed using the TYPO3 API (ProcessedFileRepository) and TYPO3 will
transparently regenerate images the next time they are actually requested.
As a safety measure, the command refuses to run without at least one filter, so you can not accidentally delete all processed files with a single call.
Examples
Preview (dry-run) which processed files would be removed for a given folder, without deleting anything yet:
./vendor/bin/typo3 cleanup:processedimages --folder="user_upload/" --dry-run
Remove all processed files that were generated with a specific crop variant. This is handy after you changed the crop configuration of a project:
./vendor/bin/typo3 cleanup:processedimages -c cropVariant=square
Combine multiple filters (they are combined with a logical AND) and limit the amount of deleted files per run, which is useful in bigger projects to keep the server load under control:
./vendor/bin/typo3 cleanup:processedimages -f "user_upload/campaigns/" -c width=1000 --limit=500
Further filters like --storage, --file-uid and --identifier are available too. A detailed description and more
examples are available in the README on GitHub.
The extension is meant to be used as an admin tool to remove processed files individually based on given constraints.
Feedback
The extension is open source, released under the GPL and compatible with TYPO3 13.4 and 14.3. Bug reports, pull requests or new ideas for improvements are always very welcome. Please use the GitHub issue tracker to share your feedback or suggestions.
