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

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions piexif/_dump.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import copy
import numbers
import struct
import sys

from ._common import *
from ._exif import *


TIFF_HEADER_LENGTH = 8

_PY2 = sys.version_info[0] == 2


def dump(exif_dict_original):
"""
Expand Down Expand Up @@ -190,8 +193,17 @@ def _value_to_bytes(raw_value, value_type, offset):
if value_type == TYPES.Byte:
length = len(raw_value)
if length <= 4:
value_str = (_pack_byte(*raw_value) +
b"\x00" * (4 - length))
if _PY2:
if isinstance(raw_value, str):
raw_value_ints = struct.unpack('<' + ('B' * length), raw_value)
else:
# assumes that it's a tuple/list of ints already
raw_value_ints = raw_value
else:
# TODO: should we check for a bytes object in this case on python3?
raw_value_ints = raw_value
value_str = (_pack_byte(*raw_value_ints) +
b"\x00" * (4 - length))
else:
value_str = struct.pack(">I", offset)
four_bytes_over = _pack_byte(*raw_value)
Expand Down