Skip to content

Commit

Permalink
chore: document types
Browse files Browse the repository at this point in the history
  • Loading branch information
lodev09 committed Mar 14, 2024
1 parent 88da67f commit 7c63d9d
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 15 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down
1 change: 0 additions & 1 deletion android/src/main/java/com/exify/ExifyModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ class ExifyModule(reactContext: ReactApplicationContext) :
}

params.putString("uri", uri)
params.putString("assetId", null)
params.putMap("tags", formatTags(exif))

exif.saveAttributes()
Expand Down
7 changes: 3 additions & 4 deletions ios/Exify.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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),
])

Expand Down Expand Up @@ -105,7 +105,6 @@ class Exify: NSObject {

resolve([
"uri": uri,
"assetId": nil,
"tags": getExifTags(from: metadata),
])

Expand Down
6 changes: 3 additions & 3 deletions ios/ExifyUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

16 changes: 11 additions & 5 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/**
* From Android's ExifInterface Tags
* Normalized for both IOS and Android
*/
export interface ExifTags {
SensorLeftBorder?: number
Expand Down Expand Up @@ -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
}

0 comments on commit 7c63d9d

Please sign in to comment.