hMatoba / Piexif

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

AsShotNeutral tag parse failure #86

Open wamslers opened 5 years ago

wamslers commented 5 years ago

The parsing of tag 50728 AsShotNeutral fails in my images. An example image is posted here:

CRW_3174p

('0th', 'AsShotNeutral', ((1000, 1693), (1000, 990), (1000, 1442)))

def test(): exif_dict = piexif.load("ImageName.jpg") exif_bytes = piexif.dump(exif_dict)

Traceback (most recent call last): File "meta.py", line 60, in test() File "meta.py", line 56, in test exif_bytes = piexif.dump(exif_dict) File "/usr/lib/python2.7/site-packages/piexif/_dump.py", line 63, in dump zeroth_set = _dict_to_bytes(zeroth_ifd, "0th", 0) File "/usr/lib/python2.7/site-packages/piexif/_dump.py", line 337, in _dict_to_bytes offset) File "/usr/lib/python2.7/site-packages/piexif/_dump.py", line 205, in _value_to_bytes four_bytes_over = _pack_short(raw_value) File "/usr/lib/python2.7/site-packages/piexif/_dump.py", line 168, in _pack_short return struct.pack(">" + "H" len(args), *args) struct.error: cannot convert argument to integer

blaueente commented 11 months ago

The AsShotNeutral seems to be part of the .dng raw image format, and kept when converting to .jpg.

a workaround seems to be: del exif_dict["0th"][piexif.ImageIFD.AsShotNeutral] # <---- ADD THIS LINE

(See also https://ru.stackoverflow.com/questions/1046656/piexif-%d0%97%d0%b0%d0%bf%d0%b8%d1%81%d1%8c-%d0%bc%d0%b5%d1%82%d0%b0%d0%b4%d0%b0%d0%bd%d0%bd%d1%8b%d1%85-%d0%b2-%d1%84%d0%be%d1%82%d0%be/1378108#1378108 )

egnor commented 5 months ago

I believe this is because _exif.py has

50728: {'name': 'AsShotNeutral', 'type': TYPES.Short},

but it should be

50728: {'name': 'AsShotNeutral', 'type': TYPES.Rational},

(let me know if I should make a PR for this)