Make WordPress Core

Opened 4 weeks ago

Closed 2 weeks ago

Last modified 7 days ago

#65618 closed defect (bug) (fixed)

REST API: Apply unapplied EXIF orientation before image edits

Reported by: ramonopoly Owned by: ramonopoly
Priority: normal Milestone: 7.1
Component: Editor Version:
Severity: normal Keywords: has-patch gutenberg-merge has-unit-tests
Cc: Focuses:

Description

This ticket tracks the backport of https://github.com/WordPress/gutenberg/pull/80144

## What

Fixes image edits (rotate, crop, flip) landing in the wrong frame for photos whose EXIF orientation tag was never applied to their pixels, most visibly iPhone JPEGs. Rotating such a photo in the media editor modal or the Image block cropper previously appeared to do nothing.

## Why

The /wp/v2/media/{id}/edit endpoint edits the file from wp_get_original_image_path(). That original often still carries an unapplied EXIF orientation tag: client-side uploads preserve it deliberately, and server-side uploads only bake the rotation into the scaled copy, never the original.

Browsers apply the tag when rendering, so clients build their edit modifiers against the upright preview while the server applies them to the raw, unrotated pixels.

For an orientation 6 photo, a 90° rotation request produced pixels identical to what the user was already seeing, so the edit looked like a no-op. Crops had the same frame mismatch

See Gutenberg conversation #77582 (comment)

Change History (8)

#1 @ramonopoly
4 weeks ago

  • Keywords has-unit-tests added

@andrewserong commented on PR #12492:


3 weeks ago
#2

Thank you for trying this out! I haven't gotten to review this properly yet as I wanted to get to the bottom of the other EXIF rotation bug we ran into. I have a tentative fix for it over in https://github.com/WordPress/gutenberg/pull/80295... I don't _think_ it'll wind up causing any differences for this PR, but just linking to it as it's thematically linked (trying to make sure we handle EXIF rotation correctly).

@adamsilverstein commented on PR #12492:


2 weeks ago
#4

This is testing nicely for me, and crops of EXIF rotated images appear to be working nicely now where they weren't before. And it's a no-op for files that didn't have any rotation applied 👍

Thanks for testing, I'm in favor of getting this in for 7.1 during the beta cycle.

@ramonopoly commented on PR #12492:


2 weeks ago
#5

Thanks folks!

#6 @ramonopoly
2 weeks ago

  • Owner set to ramonopoly
  • Resolutionfixed
  • Status newclosed

In 62820:

Attachments REST API: Apply unapplied EXIF orientation before image edits

Fixes image edits (rotate, crop, flip) landing in the wrong frame for photos whose EXIF orientation tag was never applied to their pixels, most visibly iPhone JPEGs. Rotating such a photo in the media editor modal or the Image block cropper previously appeared to do nothing.

WP_REST_Attachments_Controller::edit_media_item() edits the image from wp_get_original_image_path(). That original image often still carries an unapplied EXIF orientation tag.

WP_REST_Attachments_Controller::edit_media_item() now calls $image_editor->maybe_exif_rotate() before modifying the image for cropping.

Developed in: https://github.com/WordPress/wordpress-develop/pull/12492(https://github.com/WordPress/wordpress-develop/pull/12492)

Props ramonopoly, andrewserong, adamsilverstein.

Fixes #65618.

@ramonopoly commented on PR #12492:


2 weeks ago
#7

Committed in r62820](https://core.trac.wordpress.org/changeset/62820) / 984563262deb77d6dac1d5f7e94ca7dc405815c2

#8 @sabernhardt
7 days ago

  • Milestone Awaiting Review7.1
Note: See TracTickets for help on using tickets.