diff --git a/README.md b/README.md index 1e1c048..a12613a 100644 --- a/README.md +++ b/README.md @@ -44,8 +44,9 @@ console.log(result.tags) See [example](example) for more detailed usage. -💡 Note: On IOS, writing exif into an Asset file will duplicate the image. -Try to write to a local file first before saving! +ℹ️ Note that on IOS, writing exif into an Asset file will duplicate the image. IOS does not allow writing exif into an Asset file directly. + +If you're getting the photo from a [camera](https://github.com/mrousavy/react-native-vision-camera/), write it into the output file first before saving to the Asset library! ## Contributing Contributions are welcome! diff --git a/android/src/main/java/com/exify/ExifyModule.kt b/android/src/main/java/com/exify/ExifyModule.kt index baae0bd..6d84a1a 100644 --- a/android/src/main/java/com/exify/ExifyModule.kt +++ b/android/src/main/java/com/exify/ExifyModule.kt @@ -80,7 +80,6 @@ class ExifyModule(reactContext: ReactApplicationContext) : } params.putString("uri", uri) - params.putString("assetId", null) params.putMap("tags", formatTags(exif)) exif.saveAttributes() diff --git a/ios/Exify.swift b/ios/Exify.swift index 4c15b4d..a2a3b79 100644 --- a/ios/Exify.swift +++ b/ios/Exify.swift @@ -71,10 +71,10 @@ class Exify: NSObject { request.addResource(with: .photo, data: data, options: nil) request.creationDate = Date() - let assetId = request.placeholderForCreatedAsset!.localIdentifier + let newAssetId = request.placeholderForCreatedAsset!.localIdentifier resolve([ - "uri": "ph://\(assetId)", - "assetId": assetId, + "uri": "ph://\(newAssetId)", + "assetId": newAssetId, "tags": getExifTags(from: metadata), ]) @@ -105,7 +105,6 @@ class Exify: NSObject { resolve([ "uri": uri, - "assetId": nil, "tags": getExifTags(from: metadata), ]) diff --git a/ios/ExifyUtils.swift b/ios/ExifyUtils.swift index 5ea1049..8721ab5 100644 --- a/ios/ExifyUtils.swift +++ b/ios/ExifyUtils.swift @@ -122,14 +122,14 @@ func updateMetadata(url: URL, with tags: [String: Any], completionHanlder: (NSDi let destinationData = NSMutableData() - guard let uiImage = UIImage(contentsOfFile: url.path), - let sourceType = CGImageSourceGetType(cgImageSource), + guard let sourceType = CGImageSourceGetType(cgImageSource), let destination = CGImageDestinationCreateWithData(destinationData, sourceType, 1, nil) else { return } - CGImageDestinationAddImage(destination, uiImage.cgImage!, metadata) + CGImageDestinationAddImageFromSource(destination, cgImageSource, 0, metadata) if CGImageDestinationFinalize(destination) { completionHanlder(metadata, destinationData as Data) } } + diff --git a/src/types.ts b/src/types.ts index 26b78bb..c0175ae 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,5 +1,6 @@ /** * From Android's ExifInterface Tags + * Normalized for both IOS and Android */ export interface ExifTags { SensorLeftBorder?: number @@ -147,15 +148,20 @@ export interface ExifTags { export interface ExifyWriteResult { /** * The URI of the image that was written. - * On IOS asset, this will be new URI created. + * On IOS: If input URI is an asset, this will be new URI created. + * + * This will return exactly the same as the input URI if the input URI is from a local file. */ - uri?: string + uri: string /** - * Media Library Asset ID + * A newly created asset ID on IOS. + * Writing exif metadata into an asset file will create a new asset file. + * + * @platform ios */ - assetId?: string | null + assetId?: string /** - * Raw EXIF data from the platform + * Normalized Exif tags */ tags?: ExifTags }