Skip to content

Commit

Permalink
added various date time properties to the exif modifier
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafael Haußmann committed Aug 26, 2024
1 parent b6d0dca commit cd93dcd
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 6 deletions.
16 changes: 14 additions & 2 deletions android/src/main/java/com/exifmodifier/ExifModifierModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ public void saveImageWithProperties(String base64ImageData, ReadableMap properti

if (
properties.hasKey("GPSLatitude") &&
properties.hasKey("GPSLongitude") &&
properties.hasKey("GPSAltitude")
properties.hasKey("GPSLongitude") &&
properties.hasKey("GPSAltitude")
) {
double latitude = Double.parseDouble(properties.getString("GPSLatitude"));
double longitude = Double.parseDouble(properties.getString("GPSLongitude"));
Expand All @@ -76,6 +76,18 @@ public void saveImageWithProperties(String base64ImageData, ReadableMap properti
mappedProperties.put(ExifInterface.TAG_USER_COMMENT, properties.getString("UserComment"));
}

if (properties.hasKey("DateTime")) {
mappedProperties.put(ExifInterface.TAG_DATETIME, properties.getString("DateTime"));
}

if (properties.hasKey("DateTimeOriginal")) {
mappedProperties.put(ExifInterface.TAG_DATETIME_ORIGINAL, properties.getString("DateTimeOriginal"));
}

if (properties.hasKey("DateTimeDigitized")) {
mappedProperties.put(ExifInterface.TAG_DATETIME_DIGITIZED, properties.getString("DateTimeDigitized"));
}

saveImageAndModifyProperties(base64ImageData, mappedProperties, promise);
} catch (Exception e) {
promise.reject("E_IMAGE_PROCESSING", e);
Expand Down
24 changes: 21 additions & 3 deletions ios/ExifModifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,26 @@ class ExifModifier: NSObject {


@objc func saveImageWithProperties(_ base64ImageData: String, properties: NSDictionary, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
let exifProperties: [String: Any] = [
kCGImagePropertyExifUserComment as String: properties["UserComment"]
].compactMapValues { $0 }

var tiffProperties: [String: Any] = [:];

if let dateTime = properties["DateTime"] as? String {
tiffProperties[kCGImagePropertyTIFFDateTime as String] = dateTime;
}

var exifProperties: [String: Any] = [:];

if let userComment = properties["UserComment"] as? String {
exifProperties[kCGImagePropertyExifUserComment as String] = userComment;
}

if let dateTimeOriginal = properties["DateTimeOriginal"] as? String {
exifProperties[kCGImagePropertyExifDateTimeOriginal as String] = dateTimeOriginal;
}

if let dateTimeDigitalized = properties["DateTimeDigitized"] as? String {
exifProperties[kCGImagePropertyExifDateTimeDigitized as String] = dateTimeDigitalized;
}

var gpsProperties: [String: Any] = [:]

Expand All @@ -87,6 +104,7 @@ class ExifModifier: NSObject {
}

let mappedProperties: NSDictionary = [
kCGImagePropertyTIFFDictionary as String: tiffProperties,
kCGImagePropertyExifDictionary as String: exifProperties,
kCGImagePropertyGPSDictionary as String: gpsProperties
]
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@lulububu/react-native-exif-modifier",
"version": "0.1.12",
"version": "0.1.13",
"description": "Allows you to modify the exif data of an image and save it.",
"main": "lib/commonjs/index",
"module": "lib/module/index",
Expand Down
3 changes: 3 additions & 0 deletions src/interfaces/ImageProperties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ export interface ImageProperties {
GPSLatitude?: string;
GPSLongitude?: string;
GPSAltitude?: string;
DateTime?: string;
DateTimeOriginal?: string;
DateTimeDigitized?: string;
}

0 comments on commit cd93dcd

Please sign in to comment.