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

EXIF Data Stripped From Images #45

Closed
jczaplew opened this issue May 29, 2018 · 19 comments · Fixed by #480
Closed

EXIF Data Stripped From Images #45

jczaplew opened this issue May 29, 2018 · 19 comments · Fixed by #480
Labels
enhancement New feature or request plugin: camera

Comments

@jczaplew
Copy link

When using the camera plugin on both Android and iOS most or all EXIF data is stripped from the image. On Android all attributes are stripped, and on iOS only Orientation, ExifIFDPointer, ColorSpace, PixelXDimension and PixelYDimension are returned.

I could see this being handled in the following ways:

A) Return an EXIF dictionary with the image path
B) Retain the original EXIF data on the image itself

I think providing both is ideal, as A) would allow the client to use the EXIF data without needing to use a third-party library for using the EXIF data within the app. Additionally, B) allows for a direct upload for server-side parsing without needing to write the EXIF data back to the image client-side.

I am using the following code to test this:

import { Plugins, CameraResultType, CameraSource } from '@capacitor/core'
const { Camera } = Plugins
import { EXIF } from 'exif-js'



async getPhoto() {
    const image  = await Camera.getPhoto({
       quality: 100,
       correctOrientation: true,
       resultType: CameraResultType.Uri,
       source: CameraSource.Prompt
    })

    EXIF.getData({ src: image.webPath }, function(error) {
        if (error) {
          console.log(error)
        }
        var allMetaData = EXIF.getAllTags(this);
        console.log('ALL TAGS - ', allMetaData)

        let lng = EXIF.getTag(this, 'GPSLongitude') || null
        let lat = EXIF.getTag(this, 'GPSLatitude') || null

        console.log('LNG - ', lng)
        console.log('LAT - ', lat)
    })
  }

I don't have experience writing Swift or Java, but if there is anything I can do to help implement this please let me know!

@mlynch
Copy link
Contributor

mlynch commented May 31, 2018

Ah good catch, we definitely should be keeping that exif data around.

@mlynch
Copy link
Contributor

mlynch commented Jun 7, 2018

@mlynch
Copy link
Contributor

mlynch commented Jun 7, 2018

So, one thing here, each platform strips geolocation info from the image if taken from the camera. That makes sense to me, otherwise it'd be a way to skirt geolocation permissions. The app should do its own geolocation checking and associate with the taken image.

However, the rest of the exif is definitely there in the info passed to us, so we can/should provide it back.

Need to look into getting full exif from photo in album, which should include geolocation I'd think

@mlynch
Copy link
Contributor

mlynch commented Jun 7, 2018

Added exif output for camera photos to Camera.getPhoto. Data returned in an exif field as a dictionary. Todo: android camera, ios/android photo library

@jczaplew
Copy link
Author

jczaplew commented Jun 7, 2018

So, one thing here, each platform strips geolocation info from the image if taken from the camera. That makes sense to me, otherwise it'd be a way to skirt geolocation permissions. The app should do its own geolocation checking and associate with the taken image.

If the app has permissions for both geolocation and photos, will the geolocation exif data not be stripped from the image?

@mlynch
Copy link
Contributor

mlynch commented Jun 7, 2018

@jczaplew not sure on that, seems to work for Android but iOS strips it. Need to do more research.

42f03909fbbcb95cfa817905680b3edb989aaff4 adds EXIF support to Android, both for camera and gallery photos.

Only thing remaining is exif for iOS camera roll photos.

@DavidWiesner
Copy link

I would like to have an implementation where the exif data will be put again in the new image. But keep in mind that some values of the exif data will be changed in the process e.g.: orientation, image width and image height

@mixuala
Copy link

mixuala commented Sep 28, 2018

I'm looking for exif support on ios as well but it was empty for resultType=CameraResultType.Uri. Not a swift expert, but I came across this:

This key is valid only when using an image picker whose source type is set to UIImagePickerController.SourceType.camera, and applies only to still images.

The value for this key is an NSDictionary object that contains the metadata of the photo that was just captured. To store the metadata along with the image in the Camera Roll, use the PHAssetChangeRequest class from the Photos framework.

see: https://developer.apple.com/documentation/uikit/uiimagepickercontroller/infokey/1619147-mediametadata

apparently, you have to use PHAsset and PHPhotoLibrary to get the metadata from the images in the photo library

@jarek104
Copy link

Any updates on this?

gbresciano referenced this issue in gbresciano/capacitor Apr 13, 2020
I made an amendment to include GPS and Orientation data in the "exit" property and also to add all the metadata to the resulting image so that the exit can be found in the jpeg file. This would solve issue #564
@gbresciano
Copy link

I modified Camera.swift to have GPS and Orientation data in the "exif" property and also in the result image's exif.

@gbresciano
Copy link

gbresciano commented Apr 14, 2020

@mlynch I've never used git before, and I don't understand how this works 😅

I made some changes to Camera.swift that sorted this out for me. Can you have a look?
gbresciano/capacitor@6334c1e

Thanks!

@jarek104
Copy link

@mlynch, if @gbresciano found a solution, is there any chance we could add this fix? This limitation is essentially stopping me from switching to ionic.

@orzel095
Copy link

@mlynch, @gbresciano solution works for me, please add this commit to master,
I will be grateful, thanks and have good day 😁

@imhoffd imhoffd transferred this issue from ionic-team/capacitor Sep 17, 2020
@imhoffd imhoffd added enhancement New feature or request plugin: camera labels Sep 17, 2020
@imhoffd imhoffd removed the triage label Sep 17, 2020
@sebastianovide
Copy link

@jarek104 have you found a workaround until when it is merged in capacitor ?

@davidofwatkins
Copy link

Was this meant to be closed? I see this has been fixed on Android above, but I'm still not able to get GPS EXIF data when taking a photo on iOS.

Unfortunately the plugin has changed significantly since the workaround posted above, and I lack the Swift/iOS knowledge to apply it to the latest version.

@jthoms1
Copy link
Member

jthoms1 commented Jul 6, 2021

@davidofwatkins Are your issues on Capacitor 2 or do they persist in Capacitor 3?

@davidofwatkins
Copy link

@jthoms1 I have only tried this on Capacitor 3, unfortunately (iOS 14.5)

@dtarnawsky
Copy link
Contributor

@davidofwatkins GPS EXIF data is not captured when accessing the Camera plugin. This is because the camera plugin does not obtain the location of the device. To capture location information you will need to do this yourself by adding the geolocation plugin, capturing the current location (before or after capturing the photo) then using this along with the image captured.

Note that the Camera app in iOS and Android both request geolocation permissions and capture location information and will include it in the EXIF of photos that are saved. This is why you see this data in photos you have selected from the photo library.

This particular issue on Cap 2 and 3 was causing all the other EXIF data to not save.
If you would like more detailed information on this it is worth looking at this repo:
https://github.com/dtarnawsky/capacitor-exif-test

@ionitron-bot
Copy link

ionitron-bot bot commented Sep 30, 2022

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of the plugin, please create a new issue and ensure the template is fully filled out.

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Sep 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request plugin: camera
Projects
None yet
Development

Successfully merging a pull request may close this issue.