hMatoba / Piexif

Exif manipulation with pure python script.
MIT License
367 stars 81 forks source link

piexif.dump() cannot handle tuple for Exif tag code 37121 (ComponentsConfiguration) #83

Open ghost opened 5 years ago

ghost commented 5 years ago

Minimal example:

import piexif
exif = piexif.load("picture.jpg")

cc = exif['Exif'].get(37121)  # ComponentsConfiguration
print(type(cc), cc)           # <class 'tuple'> (1, 2, 3, 0)

exif_bytes = piexif.dump(exif)

Raises:

ValueError: "dump" got wrong type of exif value. 37121 in Exif IFD. Got as <class 'tuple'>.

Link to ComponentsConfiguration definition

Workaround:

import piexif
exif = piexif.load("picture.jpg")

cc = exif['Exif'].get(37121)
if isinstance(cc, tuple):
    exif['Exif'][37121] = ",".join([str(v) for v in cc]).encode("ASCII")

exif_bytes = piexif.dump(exif)

Picture (taken with Samsung Galaxy S III mini): picture

ghost commented 5 years ago

This is a design flaw. piexif.dump() should be able to handle anything that piexif.load() returns. Therefore, there are two solutions:

  1. piexif.load() raises an error if it encounters an invalid type
  2. piexif.dump() should handle this case similar (to the workaround I show)
mdonahoe commented 5 years ago

I'm getting the same thing for tag 41729.

What was your solution? Just that workaround you posted, or is there a specific change suggested for piexif?

PmasonFF commented 5 years ago

Just got similar issue with tag 37380 from a Bushnell camera BS685BWYx0823F Workaround:

exif = piexif.load(src)    
exif['Exif'][37380] = (0, 1)
exif_bytes = piexif.dump(exif)
piexif.insert(exif_bytes, dst)

I assume these issues are from the camera manufactures not following the (lack of ) Exif standards correctly?

hMatoba commented 5 years ago

@PmasonFF Yes. There are some manufactures that has incorrect specification. I think Piexif checks data type when dump.

jdhao commented 5 years ago

@mdonahoe see my issue here for a dirty workaround.