Skip to content

Fix for dumping exif data loaded from images that contain a Gps Versi…#78

Open
wynnw wants to merge 1 commit intohMatoba:masterfrom
wynnw:fix/exif-dump-gps-version
Open

Fix for dumping exif data loaded from images that contain a Gps Versi…#78
wynnw wants to merge 1 commit intohMatoba:masterfrom
wynnw:fix/exif-dump-gps-version

Conversation

@wynnw
Copy link

@wynnw wynnw commented Dec 5, 2018

…onID tag

  • This puts in python2 specific conditional check into _value_to_bytes() that
    will make sure a raw_value of type str uses struct.unpack to generate int's
    to send to the _pack_byte() function, otherwise it crashes trying to create
    ints from the chars in the str object.

This crash was found when loading exif data from a picture shot with a
Canon PowerShot SX50 HS (according to the exif data), and it's Gps/VersionID
value was 2.3.0.0 but at run time was loaded as '\x02\x03\x00\x00'.

This probably needs an equivalent fix for Python 3.

I haven't added a test as I'm not sure if this is conceptually the right fix, as it could be a problem with all sorts of fields. I see you haven't addressed #67, so maybe this isn't something you want the library to deal with? Seems like there's way too many interpretations of the exif spec so I understand this is a tough problem.

My use case for using this library was to auto-rotate images using Pillow based on their exif orientiation value, update the exif data's orientation flag, and then save the updated image without losing it's exif data. Right now I'll have to throw away the exif data if there's a problem creating the new exif bytes - it would be nice if it was more reliable to load/save the exif.

What are you thoughts?

…onID tag

- This puts in python2 specific conditional check into _value_to_bytes() that
will make sure a raw_value of type str uses struct.unpack to generate int's
to send to the _pack_byte() function, otherwise it crashes trying to create
ints from the chars in the str object.

This crash was found when loading exif data from a picture shot with a
Canon PowerShot SX50 HS (according to the exif data), and it's Gps/VersionID
value was 2.3.0.0 but at run time was loaded as '\x02\x03\x00\x00'.

This probably needs an equivalent fix for Python 3.
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.06%) to 94.832% when pulling 9acce90 on wynnw:fix/exif-dump-gps-version into 48ced13 on hMatoba:master.

@Avi1git
Copy link

Avi1git commented Jan 14, 2019

Hi, I am trying to write coordinates of a different system and save the modified exif to a new image using python 3.6.

exif_dict = piexif.load(img.info['exif'])

breite = exif_dict['GPS'][piexif.GPSIFD.GPSLatitude]
lange = exif_dict['GPS'][piexif.GPSIFD.GPSLongitude]
   
breite = breite[0][0] / breite[0][1] + breite[1][0] / (breite[1][1] * 60) + breite[2][0] / (breite[2][1] * 3600)
lange = lange[0][0] / lange[0][1] + lange[1][0] / (lange[1][1] * 60) + lange[2][0] / (lange[2][1] * 3600)
x, y = pyproj.transform(wgs84, gk3, lange, breite)

exif_dict['GPS'][piexif.GPSIFD.GPSLatitude] = [ ( (int)(round(y,6) * 1000000), 1000000 ), (0, 1), (0, 1) ]
exif_bytes = piexif.dump(exif_dict)
img.save(os.path.join(outPath,fn), "jpeg", exif=exif_bytes)

I am getting struct.error: argument out of range in dump.
The GPSInfo tag looks like: {0: b'\x02\x03\x00\x00', 1: 'N', 2: ((48, 1), (48, 1), (3449322402, 70000000)), 3: 'E', 4: ((9, 1), (57, 1), (1136812930, 70000000)), 5: b'\x00', 6: (3659, 10)}

What am I doing wrong?

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

Successfully merging this pull request may close these issues.

3 participants