Open alexliggett opened 5 years ago
I probably have the same issue. My broken field is GPS['GPSHPositioningError']. iPhone treats this field as Ascii (type 2). So when we load exif data, this field is collected as Ascii (for example, b'65/1' for me). When we dump it, it tries to dump this Ascii field as it was Rational (type 5). Because in _exif.py this field is described as Rational.
We should probably either dump fields with the same type we loaded them or fix wrongly loaded types to canonical ones during dump (or right after load). Loading field by one rules and dumping by others is a way to errors.
Traceback (most recent call last):
File ".\resize.py", line 105, in <module>
byte_exif = piexif.dump(exif)
File "C:\Program Files\Python37\lib\site-packages\piexif\_dump.py", line 74, in dump
gps_set = _dict_to_bytes(gps_ifd, "GPS", zeroth_length + exif_length)
File "C:\Program Files\Python37\lib\site-packages\piexif\_dump.py", line 341, in _dict_to_bytes
'{0} in {1} IFD. Got as {2}.'.format(key, ifd, type(ifd_dict[key]))
ValueError: "dump" got wrong type of exif value.
31 in GPS IFD. Got as <class 'bytes'>.
Exif data in binary contains each data type. "load" uses it. On the other hand, to "dump" exif data, it needs some reference to convert value into binary. I use object in _exif.py that was made from the specification(http://www.cipa.jp/std/documents/e/DC-010-2012_E.pdf).
To fix type, we need very tricky code. b'65/1' or [some format that we can't unpredictable] or [other type and format] -> (65, 1)
"dump" should doubt type data that contained in exif binary? I think no.
iOS should fix it to comply with the specifications.
Hi,
Firstly thanks for the awesome work on this library, which is perfect for the project I'm working on.
Just a heads up that if you try to write strings (I know, probably a dumb idea, but one I assumed to be correct at first) to the GPS Latitude/Longitude/Altitude Key EXIF fields using .dump, the following exception is thrown:
Happy to supply more information if it will help, but I suspect its something fairly straightforward.
Cheers Alex