-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[image_picker] Fix images changing to incorrect orientation #7187
Conversation
It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat (don't just cc him here, he won't see it! He's on Discord!). If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix? Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
@cyanglaz @jmagman Any ideas on how to test this? I could use a real image to test it, but I'm struggling to get a small image with the orientation metadata in it. For example, I can take a picture on my iPhone and it will have the orientation data in it and is 260KB. If I resize it or compress it, it loses the orientation metadata. |
Can you re-add the orientation metadata with something like exiftool? There also might be some imagemagick flags that resize/compress without stripping the metadata. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Once the formatter is happy. |
* cd09d9d31 [ci] Update iOS simulator (flutter/plugins#7131) * 016c3b7f1 Roll Flutter from df41e58 to 22e17bb (28 revisions) (flutter/plugins#7186) * 7160f55e8 [ios_platform_images] Update minimum version to iOS 11 (flutter/plugins#6874) * ea048a249 [in_app_purchase] Update minimum Flutter version to 3.3 and iOS 11 (flutter/plugins#6873) * 530442456 [google_sign_in_web] Migrate to the GIS SDK. (flutter/plugins#6921) * 9a3a77e6c [image_picker] Fix images changing to incorrect orientation (flutter/plugins#7187) * 8f3419be5 Roll Flutter from 22e17bb to 298d8c7 (20 revisions) (flutter/plugins#7190)
When you take an image with an iPhone in portrait mode, it's actually taking the image in landscape mode and saving rotation information into the image's metadata. The
UIImage
class will then automatically transform the image to be the correct orientation. You can read more about it here.Now, in the plugin code, when the user resizes an image that has orientation metadata, we resize it differently to handle the rotation.
plugins/packages/image_picker/image_picker_ios/ios/Classes/FLTImagePickerImageUtil.m
Lines 86 to 105 in d699b4a
#7084 changed the plugin so that every image returns basic metadata, which includes the orientation/rotation info. However, it wasn't doing to metadata scaling process which was causing the images to get incorrect orientation.
Fixes flutter/flutter#120356.
Pre-launch Checklist
dart format
.)[shared_preferences]
pubspec.yaml
with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.CHANGELOG.md
to add a description of the change, following repository CHANGELOG style.///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.