Skip to content

Commit a7e3e14

Browse files
committed
fix: normalize EXIF tags across iOS and Android
- ISOSpeedRatings returns number[] on Android (was string) - skip invalid Orientation 0 on Android - add BodySerialNumber tag on Android - remap iOS PixelWidth/PixelHeight to PixelXDimension/PixelYDimension - serialize arrays without brackets in Android write path
1 parent dcc5a97 commit a7e3e14

5 files changed

Lines changed: 25 additions & 5 deletions

File tree

android/src/main/java/com/lodev09/exify/ExifyModule.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,9 @@ class ExifyModule(
182182
}
183183

184184
ReadableType.Array -> {
185-
exif.setAttribute(tag, tags.getArray(tag).toString())
185+
val arr = tags.getArray(tag)!!
186+
val values = (0 until arr.size()).joinToString(", ") { arr.getInt(it).toString() }
187+
exif.setAttribute(tag, values)
186188
}
187189

188190
else -> {

android/src/main/java/com/lodev09/exify/ExifyTags.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,14 @@ val EXIFY_TAGS =
7878
arrayOf("double", ExifInterface.TAG_FOCAL_LENGTH),
7979
arrayOf("string", ExifInterface.TAG_LENS_MAKE),
8080
arrayOf("string", ExifInterface.TAG_LENS_MODEL),
81+
arrayOf("string", ExifInterface.TAG_BODY_SERIAL_NUMBER),
8182
arrayOf("array", ExifInterface.TAG_LENS_SPECIFICATION),
8283
arrayOf("int", ExifInterface.TAG_FOCAL_LENGTH_IN_35MM_FILM),
8384
arrayOf("int", ExifInterface.TAG_FOCAL_PLANE_RESOLUTION_UNIT),
8485
arrayOf("double", ExifInterface.TAG_FOCAL_PLANE_X_RESOLUTION),
8586
arrayOf("double", ExifInterface.TAG_FOCAL_PLANE_Y_RESOLUTION),
8687
arrayOf("int", ExifInterface.TAG_GAIN_CONTROL),
87-
arrayOf("string", ExifInterface.TAG_ISO_SPEED_RATINGS),
88+
arrayOf("int_array", ExifInterface.TAG_ISO_SPEED_RATINGS),
8889
arrayOf("string", ExifInterface.TAG_IMAGE_UNIQUE_ID),
8990
arrayOf("int", ExifInterface.TAG_LIGHT_SOURCE),
9091
arrayOf("string", ExifInterface.TAG_MAKER_NOTE),

android/src/main/java/com/lodev09/exify/ExifyUtils.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,23 @@ object ExifyUtils {
1818
}
1919

2020
"int" -> {
21-
tags.putInt(tag, exif.getAttributeInt(tag, 0))
21+
val intVal = exif.getAttributeInt(tag, 0)
22+
if (tag == ExifInterface.TAG_ORIENTATION && intVal == 0) continue
23+
tags.putInt(tag, intVal)
2224
}
2325

2426
"double" -> {
2527
tags.putDouble(tag, exif.getAttributeDouble(tag, 0.0))
2628
}
2729

30+
"int_array" -> {
31+
val array = Arguments.createArray()
32+
attribute.split(", ").forEach { part ->
33+
part.trim().toIntOrNull()?.let { array.pushInt(it) }
34+
}
35+
if (array.size() > 0) tags.putArray(tag, array)
36+
}
37+
2838
"array" -> {
2939
val array = Arguments.createArray()
3040
exif.getAttributeRange(tag)?.forEach { value ->

ios/Exify.mm

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,13 @@ static void addTagEntries(CFStringRef dictionary, NSDictionary *metadata,
4242
id value = metadata[key];
4343
if (![value isKindOfClass:[NSDictionary class]] &&
4444
![key isEqualToString:compressionKey]) {
45-
tags[key] = value;
45+
NSString *mappedKey = key;
46+
if ([key isEqualToString:@"PixelWidth"]) {
47+
mappedKey = @"PixelXDimension";
48+
} else if ([key isEqualToString:@"PixelHeight"]) {
49+
mappedKey = @"PixelYDimension";
50+
}
51+
tags[mappedKey] = value;
4652
}
4753
}
4854

src/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,14 @@ export interface ExifTags {
6363
LightSource?: number;
6464
UserComment?: string;
6565
GainControl?: number;
66-
ISOSpeedRatings?: string;
66+
ISOSpeedRatings?: number[];
6767
FocalPlaneResolutionUnit?: number;
6868
FocalPlaneXResolution?: number;
6969
YCbCrCoefficients?: number;
7070
FocalLengthIn35mmFilm?: number;
7171
LensMake?: string;
7272
LensModel?: string;
73+
BodySerialNumber?: string;
7374
LensSpecification?: number[];
7475
ISO?: number;
7576
FlashpixVersion?: number[];

0 commit comments

Comments
 (0)