Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ghost opened this issue Mar 9, 2019 · 5 comments

Comments

@ghost
Copy link

ghost commented Mar 9, 2019

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 ghost changed the title piexif.dump() cannot handle tuple for code Exif tag code 37121 (ComponentsConfiguration) piexif.dump() cannot handle tuple for Exif tag code 37121 (ComponentsConfiguration) Mar 9, 2019
@ghost
Copy link
Author

ghost commented Mar 9, 2019

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
Copy link

mdonahoe commented Apr 20, 2019

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
Copy link

PmasonFF commented Jul 2, 2019

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
Copy link
Owner

hMatoba commented Jul 3, 2019

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

@jdhao
Copy link

jdhao commented Jul 31, 2019

@mdonahoe see my issue here for a dirty workaround.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants