Browse Source

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
pull/17/merge
Simon 13 years ago
parent
commit
4720001d82
  1. 18
      sigal/image.py
  2. BIN
      tests/sample/dir1/test1/archlinux-kiss-1024x640.png
  3. 2
      tests/sample/dir1/test1/index.md
  4. 4
      tests/test_gallery.py

18
sigal/image.py

@ -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

Binary file not shown.

After

Width:  |  Height:  |  Size: 174 KiB

2
tests/sample/dir1/test1/index.md

@ -0,0 +1,2 @@
Title: An example sub-category
Thumbnail: 11.jpg

4
tests/test_gallery.py

@ -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',

Loading…
Cancel
Save