Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: the fileSize of the selected image is bigger than the origin one in ios #2006

Merged

Conversation

ntdiary
Copy link
Contributor

@ntdiary ntdiary commented Jul 22, 2022

  • Explain the motivation for making this change.
  • Provide a test plan demonstrating that the code is solid.
  • Match the code formatting of the rest of the codebase.
  • Target the main branch, NOT a "stable" branch.

Motivation (required)

This PR fixes a bug described in issue 1894.
the binary data returned by UIImageJPEGRepresentation and UIImagePNGRepresentation is much larger than
the original file.
this PR will use the original data first if user doesn't pass maxWidth, maxHeight and quality

Test Plan (required)

prepare a image:

  1. save the above png image in a device.
  2. run example app in the device ( Team and Bundle Identifier may need to be configured first).
  3. click Select Image to select the above image
  4. compare fileSize in the screen with the value in the Photo ( or use ls -l to check the saved image size)
  5. click Take image and compare the two values again

In addition,
there is an issue in the react-native library when used for upload,
I've provided a temporary solution here

@mountiny
Copy link

mountiny commented Aug 2, 2022

cc @Johan-dutoit hello! I hope we would be able to get this PR merged as we believe it resolves the problem with the increased image size on iOS. Thank you for leaving a review here!

@Johan-dutoit Johan-dutoit merged commit 6157225 into react-native-image-picker:main Aug 8, 2022
Johan-dutoit pushed a commit that referenced this pull request Aug 8, 2022
## [4.8.5](v4.8.4...v4.8.5) (2022-08-08)

### Bug Fixes

* the fileSize of the selected image is bigger than the origin one in IOS ([#2006](#2006)) ([6157225](6157225))
@Johan-dutoit
Copy link
Collaborator

🎉 This PR is included in version 4.8.5 🎉

The release is available on:

Your semantic-release bot 📦🚀

@mountiny
Copy link

mountiny commented Aug 8, 2022

Thank @Johan-dutoit for a quick help 🙌

@s77rt
Copy link
Contributor

s77rt commented Nov 22, 2022

Can we revert this? the returned data size is not correct if the quality is 1 #2052
Getting the size double seems logical and can be reduced by using a lower quality e.g. 0.95

@mountiny
Copy link

@s77rt can you elaborate on why double the size of original file is an expected output? I think the image picked should have the same size as the image in gallery

@s77rt
Copy link
Contributor

s77rt commented Nov 22, 2022

@mountiny I think it only seems double because apple stores images in heic format and the conversion from heic to jpeg is not efficient thus the large size.

Comment on lines +143 to +149
float quality = [self.options[@"quality"] floatValue];
if (![image isEqual:newImage] || (quality >= 0 && quality < 1)) {
if ([fileType isEqualToString:@"jpg"]) {
data = UIImageJPEGRepresentation(newImage, quality);
} else if ([fileType isEqualToString:@"png"]) {
data = UIImagePNGRepresentation(newImage);
}
Copy link
Contributor

@s77rt s77rt Nov 24, 2022

Choose a reason for hiding this comment

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

@Johan-dutoit Sorry for the ping.
Can you take a quick look at this, I think we should revert this part (get ride of the first condition)
Still investigating, this PR introduced the issue but the root cause exists long before...
Details posted on #2052

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants