Skip to content
Permalink
Browse files

fix #2323

  • Loading branch information
ralsina committed Jul 19, 2016
1 parent f10b808 commit dba59473889771fc81607b96494dedd9fa209a64
Showing with 39 additions and 40 deletions.
  1. +2 −1 CHANGES.txt
  2. +37 −39 nikola/image_processing.py
@@ -4,7 +4,7 @@ New in master
Features
--------

* New EXIF_WHITELIST option to filter EXIF data.
* New EXIF_WHITELIST option to filter EXIF data (Issue #2323)
* Support ``date`` filtering in the post list directive
(Issue #1889)
* Support ``doc`` shortcode (equivalent to reST ``doc`` role — part of
@@ -17,6 +17,7 @@ Features
Bugfixes
--------

* Some images were copied ignoring the PRESERVE_EXIF_DATA option
* Improved EXIF orientation handling
* Register post list template as a dependency (Issue #2391)
* Fix section color hashing when using Python 2
@@ -108,46 +108,44 @@ def resize_image(self, src, dst, max_size, bigger_panoramas=True, preserve_exif_
if bigger_panoramas and w > 2 * h:
size = min(w, max_size * 4), min(w, max_size * 4)

try:
exif = piexif.load(im.info["exif"])
except KeyError:
exif = None
# Inside this if, we can manipulate exif as much as
# we want/need and it will be preserved if required
if exif is not None:
# Rotate according to EXIF
value = exif['0th'].get(piexif.ImageIFD.Orientation, 1)
if value in (3, 4):
im = im.rotate(180)
elif value in (5, 6):
im = im.rotate(270)
elif value in (7, 8):
im = im.rotate(90)
if value in (2, 4, 5, 7):
im = ImageOps.mirror(im)
exif['0th'][piexif.ImageIFD.Orientation] = 1
try:
exif = piexif.load(im.info["exif"])
except KeyError:
exif = None
# Inside this if, we can manipulate exif as much as
# we want/need and it will be preserved if required
if exif is not None:
# Rotate according to EXIF
value = exif['0th'].get(piexif.ImageIFD.Orientation, 1)
if value in (3, 4):
im = im.rotate(180)
elif value in (5, 6):
im = im.rotate(270)
elif value in (7, 8):
im = im.rotate(90)
if value in (2, 4, 5, 7):
im = ImageOps.mirror(im)
exif['0th'][piexif.ImageIFD.Orientation] = 1

try:
im.thumbnail(size, Image.ANTIALIAS)
if exif is not None and preserve_exif_data:
# Put right size in EXIF data
w, h = im.size
if '0th' in exif:
exif["0th"][piexif.ImageIFD.ImageWidth] = w
exif["0th"][piexif.ImageIFD.ImageLength] = h
if 'Exif' in exif:
exif["Exif"][piexif.ExifIFD.PixelXDimension] = w
exif["Exif"][piexif.ExifIFD.PixelYDimension] = h
# Filter EXIF data as required
exif = self.filter_exif(exif, exif_whitelist)
im.save(dst, exif=piexif.dump(exif))
else:
im.save(dst)
except Exception as e:
self.logger.warn("Can't thumbnail {0}, using original "
"image as thumbnail ({1})".format(src, e))
utils.copy_file(src, dst)
else: # Image is small
try:
im.thumbnail(size, Image.ANTIALIAS)
if exif is not None and preserve_exif_data:
# Put right size in EXIF data
w, h = im.size
if '0th' in exif:
exif["0th"][piexif.ImageIFD.ImageWidth] = w
exif["0th"][piexif.ImageIFD.ImageLength] = h
if 'Exif' in exif:
exif["Exif"][piexif.ExifIFD.PixelXDimension] = w
exif["Exif"][piexif.ExifIFD.PixelYDimension] = h
# Filter EXIF data as required
exif = self.filter_exif(exif, exif_whitelist)
im.save(dst, exif=piexif.dump(exif))
else:
im.save(dst)
except Exception as e:
self.logger.warn("Can't process {0}, using original "
"image! ({1})".format(src, e))
utils.copy_file(src, dst)

def resize_svg(self, src, dst, max_size, bigger_panoramas):

0 comments on commit dba5947

Please sign in to comment.