Bugfix for PNG files which don't have exif metadata (closes #11).
- add a test for the _getexif method - add a png file in the sample directory
This commit is contained in:
@@ -52,14 +52,16 @@ class Image(object):
|
||||
self.img = PILImage.open(fp)
|
||||
self.img.load()
|
||||
|
||||
exif = self.img._getexif()
|
||||
if exif:
|
||||
# see: http://www.impulseadventure.com/photo/exif-orientation.html
|
||||
orientation = exif.get(EXIF_ORIENTATION_TAG)
|
||||
rotate_map = {3: 180, 6: -90, 8: 90}
|
||||
rotation = rotate_map.get(orientation)
|
||||
if rotation:
|
||||
self.img = self.img.rotate(rotation)
|
||||
if hasattr(self.img, '_getexif'):
|
||||
exif = self.img._getexif()
|
||||
|
||||
if exif:
|
||||
# http://www.impulseadventure.com/photo/exif-orientation.html
|
||||
orientation = exif.get(EXIF_ORIENTATION_TAG)
|
||||
rotate_map = {3: 180, 6: -90, 8: 90}
|
||||
rotation = rotate_map.get(orientation)
|
||||
if rotation:
|
||||
self.img = self.img.rotate(rotation)
|
||||
|
||||
def save(self, filename, **kwargs):
|
||||
"""Save the image.
|
||||
|
||||
BIN
tests/sample/dir1/test1/archlinux-kiss-1024x640.png
Normal file
BIN
tests/sample/dir1/test1/archlinux-kiss-1024x640.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 174 KiB |
2
tests/sample/dir1/test1/index.md
Normal file
2
tests/sample/dir1/test1/index.md
Normal file
@@ -0,0 +1,2 @@
|
||||
Title: An example sub-category
|
||||
Thumbnail: 11.jpg
|
||||
@@ -20,9 +20,9 @@ REF = {
|
||||
'img': '',
|
||||
},
|
||||
'dir1/test1': {
|
||||
'title': 'Test1',
|
||||
'title': 'An example sub-category',
|
||||
'thumbnail': '11.jpg',
|
||||
'img': ['11.jpg'],
|
||||
'img': ['11.jpg', 'archlinux-kiss-1024x640.png'],
|
||||
},
|
||||
'dir1/test2': {
|
||||
'title': 'Test2',
|
||||
|
||||
Reference in New Issue
Block a user