Skip to content

EXIF value types are not considered properly. #2

@ER-lee-byeoksan

Description

@ER-lee-byeoksan

I'm trying to work around orientation issue from react-native-vision-camera with the following code snippet and I found that EXIF tag Orientation is not updated properly.

async function fixRotation(file: PhotoFile) {
  const uri = `file://${file.path}`;
  const tags = await Exify.readAsync(uri);

  if (tags?.Orientation != null && tags.Orientation !== 0) {
    return;
  }

  // See https://exiftool.org/TagNames/EXIF.html
  const Orientation = {
    portrait: 1,
    'portrait-upside-down': 3,
    'landscape-left': 8, // sensor orientation is 90
    'landscape-right': 6, // sensor orientation is 270
  }[file.orientation];

  await Exify.writeAsync(`file://${file.path}`, {
    Orientation,
  });
}

I think the reason is that Orientation tag accepts integer but the native module updates as floating point value.

for ((_, tag) in EXIFY_TAGS) {
if (!tags.hasKey(tag)) continue
val type = tags.getType(tag)
when (type) {
ReadableType.Boolean -> exif.setAttribute(tag, tags.getBoolean(tag).toString())
ReadableType.Number -> exif.setAttribute(tag, tags.getDouble(tag).toBigDecimal().toPlainString())
ReadableType.String -> exif.setAttribute(tag, tags.getString(tag))
ReadableType.Array -> exif.setAttribute(tag, tags.getArray(tag).toString())
else -> exif.setAttribute(tag, tags.getString(tag))
}
}

I checked that the following code snippet updates Orientation tag well but I didn't test with iOS because I have no background with iOS dev.

        for ((valType, tag) in EXIFY_TAGS) {
          if (!tags.hasKey(tag)) continue

          val type = tags.getType(tag)

          when (type) {
            ReadableType.Boolean -> exif.setAttribute(tag, tags.getBoolean(tag).toString())
            ReadableType.Number ->
            when (valType) {
              "double" -> exif.setAttribute(tag, tags.getDouble(tag).toBigDecimal().toPlainString())
              else -> exif.setAttribute(tag, tags.getDouble(tag).toInt().toString())
            }
            ReadableType.String -> exif.setAttribute(tag, tags.getString(tag))
            ReadableType.Array -> exif.setAttribute(tag, tags.getArray(tag).toString())
            else -> exif.setAttribute(tag, tags.getString(tag))
          }
        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions