[wp-trac] [WordPress Trac] #14459: Rotate Full Size Images on Upload
WordPress Trac
noreply at wordpress.org
Sat Sep 7 20:35:11 UTC 2019
#14459: Rotate Full Size Images on Upload
-------------------------------------------------+-------------------------
Reporter: mrroundhill | Owner:
| mikeschroder
Type: enhancement | Status: reviewing
Priority: normal | Milestone: 5.3
Component: Media | Version: 3.0
Severity: normal | Resolution:
Keywords: has-patch needs-testing needs-unit- | Focuses:
tests |
-------------------------------------------------+-------------------------
Comment (by azaozz):
With #47872 and #47873 already in, thinking the way forward with EXIF
rotations in finally "open". Thinking it would be good to summarize all
options :)
The "base requirement" is that the original image should be unchanged. It
would be ideal if we can always write the EXIF data after rotating the
image.
Doing that from PHP by using [https://github.com/pel/pel PEL] (or a subset
if it) seems the best option. However that would require a lot of non-
trivial testing (i.e. write EXIF data in PHP then check if the image file
is not corrupted in any way), especially with old, possibly obscure image
files. We can't afford corrupting an image while processing it after
upload, no matter what :)
The alternative is to rotate the original image only when ImageMagick is
available and it can write EXIF, see the part of [40135] with
`is_callable( setImageOrientation ) ...`.
Then the "safest", most compatible option is to just leave the original
image as-is and only rotate sub-sizes.
A typical case:
- User uploads an image with EXIF Orientation != 1.
- The first thing that happens after the attachment post is created is the
check for "BIG" image, #47873. By that time the EXIF data is already
retrieved. Then:
- If the image is big, scale it down and rotate it.
- If the image is not big, or if scaling of big images is disabled (by a
plugin), rotate it and save a copy. This will use the same way of keeping
the original image as with big images.
- Image sub-sizes are created from the original image for best quality.
The `make_subsize()` method in the image editor can be extended to look
into EXIF and rotate the image before or after resizing.
There are couple of variations. Generally it may be faster (use less
resources) if each sub-size is rotated after the resizing. Of course that
would depend on how many sub-sizes are being created. However this would
not work for cropped images, the source would have to be rotated before
cropping.
Seems best to stick to rotating the source before resizing and then
creating all sub-sizes from the rotated source.
On the implementation side, thinking `WP_Image_Editor` will need a
`maybe_exif_rotate()` method that is called before any (batch) cropping or
resizing is done with `make_subsize()`, and possibly before `resize()`.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/14459#comment:84>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list