Skip to content

Commit

Permalink
Ver 1.0.11
Browse files Browse the repository at this point in the history
  • Loading branch information
hMatoba committed Jan 22, 2017
1 parent a8d397f commit 9fee596
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 3 deletions.
5 changes: 5 additions & 0 deletions doc/changes.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Changelog
=========

1.0.11
------

- Add option argument to "load".

1.0.10
------

Expand Down
2 changes: 1 addition & 1 deletion doc/functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Functions

load
----
.. py:function:: piexif.load(filename)
.. py:function:: piexif.load(filename, key_is_name=False)
Return exif data as dict. Keys(IFD name), be contained, are "0th", "Exif", "GPS", "Interop", "1st", and "thumbnail". Without "thumbnail", the value is dict(tag/value). "thumbnail" value is JPEG as bytes.

Expand Down
2 changes: 1 addition & 1 deletion piexif/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
from ._exif import *


VERSION = '1.0.10'
VERSION = '1.0.11'
17 changes: 16 additions & 1 deletion piexif/_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
LITTLE_ENDIAN = b"\x49\x49"


def load(input_data):
def load(input_data, key_is_name=False):
"""
py:function:: piexif.load(filename)
Expand Down Expand Up @@ -55,6 +55,9 @@ def load(input_data):
exif_dict["1st"][ImageIFD.JPEGInterchangeFormatLength])
thumb = exifReader.tiftag[exif_dict["1st"][ImageIFD.JPEGInterchangeFormat]:end]
exif_dict["thumbnail"] = thumb

if key_is_name:
exif_dict = _get_key_name_dict(exif_dict)
return exif_dict


Expand Down Expand Up @@ -215,3 +218,15 @@ def convert_value(self, val):
return data[0]
else:
return data


def _get_key_name_dict(exif_dict):
new_dict = {
"0th":{TAGS["Image"][n]["name"]:value for n, value in exif_dict["0th"].items()},
"Exif":{TAGS["Exif"][n]["name"]:value for n, value in exif_dict["Exif"].items()},
"1st":{TAGS["Image"][n]["name"]:value for n, value in exif_dict["1st"].items()},
"GPS":{TAGS["GPS"][n]["name"]:value for n, value in exif_dict["GPS"].items()},
"Interop":{TAGS["Interop"][n]["name"]:value for n, value in exif_dict["Interop"].items()},
"thumbnail":exif_dict["thumbnail"],
}
return new_dict
23 changes: 23 additions & 0 deletions tests/s_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,29 @@ def test_load_from_pilImage_property(self):
o.seek(0)
Image.open(o).close()

def test_load_name_dict(self):
thumbnail_io = io.BytesIO()
thumb = Image.open(INPUT_FILE2)
thumb.thumbnail((40, 40))
thumb.save(thumbnail_io, "JPEG")
thumb.close()
thumb_data = thumbnail_io.getvalue()
exif_dict = {"0th":ZEROTH_IFD,
"Exif":EXIF_IFD,
"GPS":GPS_IFD,
"Interop":INTEROP_IFD,
"1st":FIRST_IFD,
"thumbnail":thumb_data}
exif_bytes = piexif.dump(exif_dict)
im = Image.new("RGBA", (80, 80))

o = io.BytesIO()
im.save(o, format="jpeg", exif=exif_bytes)
im.close()
o.seek(0)
exif = piexif.load(o.getvalue(), True)
print(exif)

# dump ------
def test_no_exif_dump(self):
o = io.BytesIO()
Expand Down

0 comments on commit 9fee596

Please sign in to comment.