@lodev09/react-native-exify 0.2.1 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -42,10 +42,11 @@ const result = await writeAsync(uri, newTags)
|
|
|
42
42
|
console.log(result.tags)
|
|
43
43
|
```
|
|
44
44
|
|
|
45
|
-
|
|
45
|
+
> **Note**:
|
|
46
|
+
> On IOS, writing exif into an Asset file will duplicate the image. IOS does not allow writing exif into an Asset file directly.
|
|
47
|
+
> 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!
|
|
46
48
|
|
|
47
|
-
|
|
48
|
-
Try to write to a local file first before saving!
|
|
49
|
+
See [example](example) for more detailed usage.
|
|
49
50
|
|
|
50
51
|
## Contributing
|
|
51
52
|
Contributions are welcome!
|
package/ios/Exify.swift
CHANGED
|
@@ -71,10 +71,10 @@ class Exify: NSObject {
|
|
|
71
71
|
request.addResource(with: .photo, data: data, options: nil)
|
|
72
72
|
request.creationDate = Date()
|
|
73
73
|
|
|
74
|
-
let
|
|
74
|
+
let newAssetId = request.placeholderForCreatedAsset!.localIdentifier
|
|
75
75
|
resolve([
|
|
76
|
-
"uri": "ph://\(
|
|
77
|
-
"assetId":
|
|
76
|
+
"uri": "ph://\(newAssetId)",
|
|
77
|
+
"assetId": newAssetId,
|
|
78
78
|
"tags": getExifTags(from: metadata),
|
|
79
79
|
])
|
|
80
80
|
|
|
@@ -105,7 +105,6 @@ class Exify: NSObject {
|
|
|
105
105
|
|
|
106
106
|
resolve([
|
|
107
107
|
"uri": uri,
|
|
108
|
-
"assetId": nil,
|
|
109
108
|
"tags": getExifTags(from: metadata),
|
|
110
109
|
])
|
|
111
110
|
|
package/ios/ExifyUtils.swift
CHANGED
|
@@ -64,6 +64,7 @@ func getExifTags(from metadata: NSDictionary) -> [String: Any] {
|
|
|
64
64
|
func readExifTags(from url: URL?, completionHandler: ([String: Any]?) -> Void) -> Void {
|
|
65
65
|
guard let url, let sourceImage = CGImageSourceCreateWithURL(url as CFURL, nil),
|
|
66
66
|
let metadataDict = CGImageSourceCopyPropertiesAtIndex(sourceImage, 0, nil) else {
|
|
67
|
+
completionHandler(nil)
|
|
67
68
|
return
|
|
68
69
|
}
|
|
69
70
|
|
|
@@ -73,6 +74,7 @@ func readExifTags(from url: URL?, completionHandler: ([String: Any]?) -> Void) -
|
|
|
73
74
|
|
|
74
75
|
func updateMetadata(url: URL, with tags: [String: Any], completionHanlder: (NSDictionary?, Data?) -> Void) -> Void {
|
|
75
76
|
guard let cgImageSource = CGImageSourceCreateWithURL(url as CFURL, nil) else {
|
|
77
|
+
completionHanlder(nil, nil)
|
|
76
78
|
return
|
|
77
79
|
}
|
|
78
80
|
|
|
@@ -81,7 +83,7 @@ func updateMetadata(url: URL, with tags: [String: Any], completionHanlder: (NSDi
|
|
|
81
83
|
|
|
82
84
|
// Append additional Exif data
|
|
83
85
|
let exifDict = metadata[kCGImagePropertyExifDictionary as String] as? NSMutableDictionary
|
|
84
|
-
exifDict
|
|
86
|
+
exifDict?.addEntries(from: tags)
|
|
85
87
|
|
|
86
88
|
// Handle GPS Tags
|
|
87
89
|
var gpsDict = [String: Any]()
|
|
@@ -125,11 +127,12 @@ func updateMetadata(url: URL, with tags: [String: Any], completionHanlder: (NSDi
|
|
|
125
127
|
guard let uiImage = UIImage(contentsOfFile: url.path),
|
|
126
128
|
let sourceType = CGImageSourceGetType(cgImageSource),
|
|
127
129
|
let destination = CGImageDestinationCreateWithData(destinationData, sourceType, 1, nil) else {
|
|
130
|
+
completionHanlder(nil, nil)
|
|
128
131
|
return
|
|
129
132
|
}
|
|
130
133
|
|
|
131
134
|
CGImageDestinationAddImage(destination, uiImage.cgImage!, metadata)
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
+
CGImageDestinationFinalize(destination)
|
|
136
|
+
|
|
137
|
+
completionHanlder(metadata, destinationData as Data)
|
|
135
138
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* From Android's ExifInterface Tags
|
|
3
|
+
* Normalized for both IOS and Android
|
|
3
4
|
*/
|
|
4
5
|
export interface ExifTags {
|
|
5
6
|
SensorLeftBorder?: number;
|
|
@@ -146,15 +147,20 @@ export interface ExifTags {
|
|
|
146
147
|
export interface ExifyWriteResult {
|
|
147
148
|
/**
|
|
148
149
|
* The URI of the image that was written.
|
|
149
|
-
* On IOS asset, this will be new URI created.
|
|
150
|
+
* On IOS: If input URI is an asset, this will be new URI created.
|
|
151
|
+
*
|
|
152
|
+
* This will return exactly the same as the input URI if the input URI is from a local file.
|
|
150
153
|
*/
|
|
151
|
-
uri
|
|
154
|
+
uri: string;
|
|
152
155
|
/**
|
|
153
|
-
*
|
|
156
|
+
* A newly created asset ID on IOS.
|
|
157
|
+
* Writing exif metadata into an asset file will create a new asset file.
|
|
158
|
+
*
|
|
159
|
+
* @platform ios
|
|
154
160
|
*/
|
|
155
|
-
assetId?: string
|
|
161
|
+
assetId?: string;
|
|
156
162
|
/**
|
|
157
|
-
*
|
|
163
|
+
* Normalized Exif tags
|
|
158
164
|
*/
|
|
159
165
|
tags?: ExifTags;
|
|
160
166
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/types.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,WAAW,QAAQ;IACvB,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,WAAW,CAAC,EAAE,MA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M,WAAW,gBAAgB;IAC/B;;;;;OAKG;IACH,GAAG,EAAE,MAAM,CAAA;IACX;;;;;OAKG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB;;OAEG;IACH,IAAI,CAAC,EAAE,QAAQ,CAAA;CAChB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lodev09/react-native-exify",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "Read and write exif data into an image.",
|
|
5
5
|
"main": "lib/commonjs/index",
|
|
6
6
|
"module": "lib/module/index",
|
|
@@ -94,7 +94,7 @@
|
|
|
94
94
|
"workspaces": [
|
|
95
95
|
"example"
|
|
96
96
|
],
|
|
97
|
-
"packageManager": "yarn@
|
|
97
|
+
"packageManager": "yarn@4.1.1",
|
|
98
98
|
"jest": {
|
|
99
99
|
"preset": "react-native",
|
|
100
100
|
"modulePathIgnorePatterns": [
|
package/src/types.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* From Android's ExifInterface Tags
|
|
3
|
+
* Normalized for both IOS and Android
|
|
3
4
|
*/
|
|
4
5
|
export interface ExifTags {
|
|
5
6
|
SensorLeftBorder?: number
|
|
@@ -147,15 +148,20 @@ export interface ExifTags {
|
|
|
147
148
|
export interface ExifyWriteResult {
|
|
148
149
|
/**
|
|
149
150
|
* The URI of the image that was written.
|
|
150
|
-
* On IOS asset, this will be new URI created.
|
|
151
|
+
* On IOS: If input URI is an asset, this will be new URI created.
|
|
152
|
+
*
|
|
153
|
+
* This will return exactly the same as the input URI if the input URI is from a local file.
|
|
151
154
|
*/
|
|
152
|
-
uri
|
|
155
|
+
uri: string
|
|
153
156
|
/**
|
|
154
|
-
*
|
|
157
|
+
* A newly created asset ID on IOS.
|
|
158
|
+
* Writing exif metadata into an asset file will create a new asset file.
|
|
159
|
+
*
|
|
160
|
+
* @platform ios
|
|
155
161
|
*/
|
|
156
|
-
assetId?: string
|
|
162
|
+
assetId?: string
|
|
157
163
|
/**
|
|
158
|
-
*
|
|
164
|
+
* Normalized Exif tags
|
|
159
165
|
*/
|
|
160
166
|
tags?: ExifTags
|
|
161
167
|
}
|