[wp-trac] [WordPress Trac] #57003: Compress original image upload to avoid uncompressed images
WordPress Trac
noreply at wordpress.org
Fri Nov 4 20:01:53 UTC 2022
#57003: Compress original image upload to avoid uncompressed images
-------------------------+-------------------------------------------------
Reporter: flixos90 | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Media | Version:
Severity: normal | Keywords: 2nd-opinion needs-patch needs-unit-
Focuses: performance | tests
-------------------------+-------------------------------------------------
When an image is uploaded to WordPress today, WordPress will generate the
sub-sized versions using compression with the default quality (e.g. 82 for
JPEG). The point of this is to offer smaller versions to achieve better
performance with different viewport sizes. The compression here is a
significant part of it, as we would not want those smaller sized images to
be badly compressed and thus overly large in file size.
A problem (and I would argue oversight) in that approach is that the
originally uploaded image is still used as is in many cases, even in the
frontend. #47873 introduced the feature to compress "big" images in a
smaller version, which makes sense, however that is only part of the
potential problem here: It can also happen that the original image upload
is simply an overly large file, even if the dimensions of the image are
smaller than what makes it qualify for a "big" image.
This ticket proposes the following:
* Always generate a new image from the originally uploaded image, even
when it is not a "big" image (potential exception could be PNGs as
currently the case, see #48736).
* Once the image has been generated, compare the file size of the new
image with the original image:
* If the new image is smaller, use that one going forward, backing up
the original image in the same way it already happens as part of the "big"
image feature.
* If the new image is larger (i.e. the original was already well
compressed), delete the new image again and simply keep the original as
is.
Given that we already generate an additional image file for "big" image
uploads, this enhancement would not introduce any concerning overhead. It
also does not make any assumptions on the original image quality, it
simply compares the results to make a decision which image to keep. In any
case, the original image will be kept so it would not be a destructive
action either.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/57003>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list