Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

[image_picker] Fix to keep Exif and so on in case of iOS.#866

Closed
ko2ic wants to merge 1 commit intoflutter:masterfrom
ko2ic:image_picker_ios_exif
Closed

[image_picker] Fix to keep Exif and so on in case of iOS.#866
ko2ic wants to merge 1 commit intoflutter:masterfrom
ko2ic:image_picker_ios_exif

Conversation

@ko2ic
Copy link
Contributor

@ko2ic ko2ic commented Oct 23, 2018

Description

The image that can be acquired with image_picker is missing some information, even in the case of the original size.

  1. CreateDate of Exif.
  2. GPSLatitude, GPSLatitude, GPSLongitudeRef , GPSLongitude of GPS Tags.
  3. Animation of GIF
  4. PNG transparency (It solves with [image_picker]Fixed losing transparency of PNGs #742, but the solution method is different )

This pull request is a modification of these.

Limitation

  • The Image of tiff and Unknown magic byte draws as JPEG. (But this has the same problem with the current version.)

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • My PR includes unit or integration tests for all changed/updated/fixed behaviors (See [Contributor Guide]).
  • All existing and new tests are passing.
  • I updated/added relevant documentation (doc comments with ///).
  • The analyzer (flutter analyze) does not report any problems on my PR.
  • I read and followed the [Flutter Style Guide].
  • The title of the PR starts with the name of the plugin surrounded by square brackets, e.g. [shared_preferences]
  • I updated pubspec.yaml with an appropriate new version according to the [pub versioning philosophy].
  • I updated CHANGELOG.md to add a description of the change.
  • I signed the [CLA].
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Does your PR require plugin users to manually update their apps to accommodate your change?

  • Yes, this is a breaking change (please indicate a breaking change in CHANGELOG.md and increment major revision).
  • No, this is not a breaking change.

@ko2ic ko2ic force-pushed the image_picker_ios_exif branch 2 times, most recently from 00a04d2 to 878b496 Compare October 24, 2018 02:05
@ko2ic ko2ic force-pushed the image_picker_ios_exif branch 2 times, most recently from f110f81 to d5f7aa4 Compare November 1, 2018 07:52
@tvolkert
Copy link
Contributor

/cc @xster

@collinjackson
Copy link
Contributor

@goderbauer I think you were looking at this issue. does it still need merging?

@goderbauer
Copy link
Member

@collinjackson I looked at (and fixed) EXIF data for the camera plugin. The image_picker uses a different API and I wouldn't be surprised if it has the same issue. So, this PR is probably still relevant.

@9thwall
Copy link

9thwall commented Dec 27, 2018

I'm running image_picker 0.4.10 on a Pixel 3 phone and the image is rotating as everyone has mentioned.
Is there a fix we can apply to resolve this?

@manhnhhdvn
Copy link

@collinjackson, @goderbauer: I need this feature, so I fetched this PR then gave it a try, and everything worked fine for me. If this PR has no problems, could you merge it asap?

@ko2ic ko2ic force-pushed the image_picker_ios_exif branch 4 times, most recently from 6a496d5 to 3d3178a Compare February 6, 2019 07:54
* Keep gps and creationDate.
* Fix to appropriate extension.
@ko2ic ko2ic force-pushed the image_picker_ios_exif branch from 3d3178a to 2282ef8 Compare February 6, 2019 09:20
@ko2ic
Copy link
Contributor Author

ko2ic commented Feb 6, 2019

I checked the operation after a long time, so I fixed it because there was a bug.

  • Fixed was not working with heic.
  • Fixed not working with first authentication permission

Are there any plans for this Pull Request to be merged?

@ko2ic
Copy link
Contributor Author

ko2ic commented Mar 1, 2019

@collinjackson This PullRequest contains fixes to PNG transparency of at least IOS.
However, merge is necessary for #742 .
This is difficult to merge. Because in my PR, I use the first of byte to judge whether it is PNG or not.( #742 use alpha info.)

If my judgment is correct, Could ios overwrite it with my source?

In addition, this pull request is useful as at least creationDate and GPS information is hold.

Could you make a review because I want to use exif by any means?

@romaluca
Copy link
Contributor

romaluca commented Mar 8, 2019

Up

@ko2ic ko2ic changed the title [image_picker] Fix to keep Exif on ios. [image_picker] Fix to keep Exif and so on in case of iOS. Apr 5, 2019
Copy link
Contributor

@cyanglaz cyanglaz left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution! :)
I ran a quick look of the PR and left some comments. I will take another deep look into the actual meta data handling logic after we made a decision on how we are going to copy the meta data after you reading my suggestion on one of my comments.


uint8_t c;
[imageData getBytes:&c length:1];
switch (c) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we make this an enum?
e.g, create a method like:

- (FlutterImagePickerFileType)getFileTypeFromFirstByte:(unit8_t c) {
   switch(c) {
      case 0x47:
        return FlutterImagePickerFileTypeGIF;
     .....
     .....
  }
}

return scaledImage;
}

- (void)createImageFileAtPath:(NSString *)path contents:(NSData *)data {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit:

Suggested change
- (void)createImageFileAtPath:(NSString *)path contents:(NSData *)data {
- (void)createImageFileAtPath:(NSString *)path data:(NSData *)data {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This mimics the signature of NSFileManager class.
So I feel good with contents.
However, I leave it to you.

- (BOOL)createFileAtPath:(NSString *)path contents:(nullable NSData *)data attributes:(nullable NSDictionary<NSFileAttributeKey, id> *)attr;

_arguments = nil;
}

- (void)createImageFileAtPath:(NSString *)path contents:(NSData *)data with:(PHAsset *)asset {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit:

Suggested change
- (void)createImageFileAtPath:(NSString *)path contents:(NSData *)data with:(PHAsset *)asset {
- (void)createImageFileAtPath:(NSString *)path data:(NSData *)data asset:(PHAsset *)asset {

}
} else {
NSURL *assetURL = [info objectForKey:UIImagePickerControllerReferenceURL];
PHFetchResult<PHAsset *> *result = [PHAsset fetchAssetsWithALAssetURLs:@[ assetURL ]
Copy link
Contributor

Choose a reason for hiding this comment

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

assetURL can be nil if user take a fresh picture in the image_picker, which leads to crash here.

}

- (void)createImageFileAtPath:(NSString *)path contents:(NSData *)data with:(PHAsset *)asset {
NSMutableDictionary *exifDict = [self fetchExifFrom:asset];
Copy link
Contributor

Choose a reason for hiding this comment

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

Manually parsing the meta data seems to be risky. Is it possible to get the meta data from the original image directly and pass down to the new image?
Maybe when fetching image in requestImageDataForAsset, we can call (NSDictionary *)CFBridgingRelease(CGImageSourceCopyPropertiesAtIndex(cgImage,0,NULL)); to get the whole meta data of the old image, and then somehow get a diff between the new image and the old image, then add the necessary stuff to the new image?
This way we don't manually parse the information like formatting time, adding hard coded GPS keys etc.

_arguments = nil;
}

- (NSMutableDictionary *)fetchExifFrom:(PHAsset *)asset {
Copy link
Contributor

Choose a reason for hiding this comment

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

If a manual parser is inevitable, let's put the meta data handling into a separate file/class.

@cyanglaz
Copy link
Contributor

cyanglaz commented May 4, 2019

@ko2ic Are you able to keep working on this PR? I think this is valuable. If you are not able to continue, do you mind me taking this over?

@cyanglaz cyanglaz self-assigned this May 4, 2019
@ko2ic
Copy link
Contributor Author

ko2ic commented May 9, 2019

@cyanglaz I will hand over to you.
You will probably get better done than I do.

@cyanglaz
Copy link
Contributor

Thanks to @ko2ic for the inspiration provided in this PR.
The issue this PR tries to fix is fixed after #1617
The only missing part is gif handling, since it is not clear that what we want to do with scaled GIFs (it seems to lose animation at this point)
I will close this PR now. If anyone has an idea to completely handle GIFs, please feel empowered to open a PR! @ko2ic

@cyanglaz cyanglaz closed this May 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants