Skip to content

Fix expo-image-manipulator cropped image orientation#55379

Closed
mlazari wants to merge 1 commit intofacebook:mainfrom
mlazari:master
Closed

Fix expo-image-manipulator cropped image orientation#55379
mlazari wants to merge 1 commit intofacebook:mainfrom
mlazari:master

Conversation

@mlazari
Copy link
Contributor

@mlazari mlazari commented Jan 30, 2026

Summary:

#54184 introduced a change that uses CGImageSourceCreateImageAtIndex instead of CGImageSourceCreateThumbnailAtIndex to decode full-sized images. However, unlike CGImageSourceCreateThumbnailAtIndex which rotates the image according to the orientation in the image's metadata, CGImageSourceCreateThumbnailAtIndex doesn't do that. Since the UIImage initializer is always passed UIImageOrientationUp for orientation, this results in the returned UIImage having wrong orientation.

This can be reproduced for example if you take a photo with react-native-vision-camera in an orientation different from "up" (e.g. taking a photo on an iPhone SE 2020 in a vertical position results in a photo with "landscape-right" orientation), then use PhotoManipulator.crop() to crop the image, then show the resulted image URI in an Image component - the image is shown in a wrong orientation.

This change fixes that by making sure the UIImage is passed the correct image orientation when CGImageSourceCreateImageAtIndex is used.

Changelog:

[IOS] [FIXED] - Fix expo-image-manipulator cropped image orientation

Test Plan:

0.82.1

https://github.com/mlazari/RNImageRepro/tree/rn-0.82.1

0.82.1.mov

0.83.1

https://github.com/mlazari/RNImageRepro/tree/0.83.1

0.83.1.mov

0.83.1 + patch with the changes in this PR

https://github.com/mlazari/RNImageRepro/tree/0.83.1-with-patch

0.83.1-with-patch.mov

facebook#54184 introduced a change that uses `CGImageSourceCreateImageAtIndex` instead of `CGImageSourceCreateThumbnailAtIndex` to decode full-sized images. However, unlike `CGImageSourceCreateThumbnailAtIndex` which rotates the image according to the orientation in the image's metadata, `CGImageSourceCreateThumbnailAtIndex` doesn't do that. Since the UIImage initializer is always passed `UIImageOrientationUp` for orientation, this results in the returned `UIImage` having wrong orientation.

This can be reproduced for example if you take a photo with `react-native-vision-camera` in an orientation different from "up" (e.g. taking a photo on an iPhone SE 2020 in a vertical position results in a photo with "landscape-right" orientation), then use PhotoManipulator.crop() to crop the image, then show the resulted image URI in an Image component - the image is shown in a wrong orientation.

This change fixes that by making sure the UIImage is passed the correct image orientation when `CGImageSourceCreateImageAtIndex` is used.
@meta-cla meta-cla bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jan 30, 2026
@facebook-github-bot facebook-github-bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Jan 30, 2026
Copy link
Contributor

@tsapeta tsapeta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry for breaking it 🙈 This change looks good to me!

Copy link
Contributor

@cipolleschi cipolleschi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix!

@meta-codesync
Copy link

meta-codesync bot commented Feb 3, 2026

@cipolleschi has imported this pull request. If you are a Meta employee, you can view this in D92148021.

@meta-codesync meta-codesync bot closed this in 978d5a2 Feb 4, 2026
@facebook-github-bot facebook-github-bot added the Merged This PR has been merged. label Feb 4, 2026
@meta-codesync
Copy link

meta-codesync bot commented Feb 4, 2026

@cipolleschi merged this pull request in 978d5a2.

@react-native-bot
Copy link
Collaborator

This pull request was successfully merged by @mlazari in 978d5a2

When will my fix make it into a release? | How to file a pick request?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants