-
Notifications
You must be signed in to change notification settings - Fork 131
Description
Following some brainstorming and discussion around the WebP efforts at WordCamp Europe, one of the key takeaways was that we should include the following enhancement in the implementation: WebP versions of an image size should only be kept if they are in fact smaller than the corresponding JPEG version.
This will certainly be the case most of the time, but in the special cases where it isn't, there is in fact no point in keeping the WebP version around. WebP versions for each size are created for their performance benefit, and if in any scenario the WebP file is larger than the JPEG file, this benefit is no longer present.
While this only has a minor impact on storage usage, the enhancement is also slightly related to that, as it helps not using any storage space wastefully. All other considerations that add to the necessary storage space are tied to a particular benefit (either performance or backward compatibility), but keeping larger WebP files around is simply wasteful and should be avoided.
The goal here is the following:
- Files of the primary MIME type (i.e. in our focused scenario usually JPEG) should always be kept.
- Files of additional MIME types (i.e. in our focused scenario usually WebP) should only be kept if they are in fact smaller than the corresponding file of the primary MIME type.
Here's the proposed implementation:
- Modify
webp_uploads_create_sources_property()
:- In both places where an additional image source file is created, its
filesize
should be immediately compared to thefilesize
of the primary MIME type file (i.e. the one that is stored already for each size and for the "full" attachment file). - If the created file has a larger
filesize
, it should be deleted again immediately (and of course not be added to thesources
map).
- In both places where an additional image source file is created, its
- PHPUnit tests should be added to verify this behavior.