imagehelper - filename (towebp, tojpg) - #2556
Conversation
|
Thanks so much @EpicKau ! It looks like some tests need to be updated to match with this new naming convention. Could you give it a look? |
|
@jarednova So what I see is that most time the test failed because of "assertFileExists" check. ("Failed asserting that file "XYZ" exists.") |
|
Exactly @EpicKau (at least, that's what it looks like) — just need to reflect the new expected naming convention |
|
So I ran into this issue #2748 as well and found this PR after some digging. #2535 seems to be related as well. I did some local tests and this pr fixes both problems for me. both the webp and and jpg generated images are removed. Only files that are not accounted for are when running towebp and tojpg on crops that will result to filenames like these. |
gchtr
left a comment
There was a problem hiding this comment.
With this change, websites that use the ToJpg and ToWebp operations will be left with quite a few stray webp and jpg images.
Do we have to consider this as a breaking change? Because I see the following problems here:
- It will trigger the images to be regenerated and for sites with a lot of images, right? This could create performance issues or even max execution time errors.
- It might have serious impact on the whole size of the website, which could lead to problems on websites that have a limited available space.
|
This is still an issue we run into every now and then. Is there an ETA for this fix? |
|
@gchtr @pascalknecht Any chance we could get this merged? The installations are getting bigger and bigger. I could also bring some 🍻 to your office. 😊 |
|
@EpicKau I tested it with WebP images generated with self::processDeleteGeneratedFiles($filename, 'webp', $dir, '-[0-9999999]*', '-[0-9]*x[0-9]*-c-[a-z]*.');
self::processDeleteGeneratedFiles($filename, 'webp', $dir, '-lbox-[0-9999999]*', '-lbox-[0-9]*x[0-9]*-[a-zA-Z0-9]*.');
// If scaled image is deleted, delete the original image webp as well
$filename_without_scaled = str_replace('-scaled', '', $filename);
self::processDeleteGeneratedFiles($filename_without_scaled, 'webp', $dir, '-[0-9999999]*', '-[0-9]*x[0-9]*-c-[a-z]*.');
self::processDeleteGeneratedFiles($filename_without_scaled, 'webp', $dir, '-lbox-[0-9999999]*', '-lbox-[0-9]*x[0-9]*-[a-zA-Z0-9]*.');With these addition we seem to catch all files. Would be great to see this implemented by default, if you need any help on this, I am happy to help with the update of the pull request. |
The |
Yes, source files that are changed to webp, but not crops that are changed to webp. Those still have to be addressed. |
|
There’s no ETA on this fix yet. Because there’s more involved here than simply merging this PR. But it is definitely something we want to work on next. As mentioned in #2556 (review), this "fix" would cause many websites to generate a lot of images, while existing images will not be deleted automatically. If we don’t classify this as a breaking change, many websites could run into problems. I wrote an answer to a similar issue in #2876 (comment), which outlines the problems we have to solve:
So, for this issue to be fixed more quickly, I think the most straight-forward way to go would be to add the fixes as an opt-in feature through a WordPress filter hook in a new PR against the 2.x branch. Something like: add_filter('timber/image/advanced_file_names', '__return_true'); |
|
@svenvonarx @marcoluzi @enrikberisha Does any one of you have the capacity to work on a basic PR for this? If we had the base code, this would surely speed up a fix for this. If you can’t include tests, that would be fine as well. We could work on those. @enrikberisha Thanks for the offer for the 🍻😄. Let’s have on at WordCamp Europe in Basel with the whole Timber team, if you can make it 😉. |
|
@gchtr I can try to come up with something. 👍🏻 |
Fixes #897
Issue
files are not deleted, when they were generated through timber filter. (webp, png)
Solution
Change generated filenames to have target fileformat in the filename.
Added more calls to delete_generated_files with specific regex for fileformat
I hope it helps.