Skip to content
Permalink
Browse files

Merge pull request #2207 from getnikola/preserve-exif

WIP Copy EXIF data to resized images (fix #2204)
  • Loading branch information
ralsina committed Feb 14, 2016
2 parents 7638ac8 + 7b4b002 commit e509a52adae1da60af2f67baec3cfb8526836926
Showing with 19 additions and 6 deletions.
  1. +1 −0 CHANGES.txt
  2. +5 −0 nikola/conf.py.in
  3. +6 −2 nikola/image_processing.py
  4. +1 −0 nikola/nikola.py
  5. +3 −2 nikola/plugins/task/galleries.py
  6. +3 −2 nikola/plugins/task/scale_images.py
@@ -16,6 +16,7 @@ Features
if ``GITHUB_COMMIT_SOURCE`` is set to True (Issue #2186)
* Hugo-like shortcodes (Issue #1707)
* New Galician translation
* New PRESERVE_EXIF_DATA option to copy EXIF when resizing images (Issue #2204)
* New facilities for data persistence and data caching (Issues #2209 and #2009)
* (internal) allow ``scripts/jinjify.py`` usage with scripts (Issue #2240)

@@ -562,6 +562,11 @@ GITHUB_COMMIT_SOURCE = True
#
# If set to False, it will sort by filename instead. Defaults to True
# GALLERY_SORT_BY_DATE = True

# If set to True, EXIF data will be copied when an image is thumbnailed or
# resized.
# PRESERVE_EXIF_DATA = False

#
# Folders containing images to be used in normal posts or pages. Images will be
# scaled down according to IMAGE_THUMBNAIL_SIZE and MAX_IMAGE_SIZE options, but
@@ -52,7 +52,7 @@ class ImageProcessor(object):

image_ext_list_builtin = ['.jpg', '.png', '.jpeg', '.gif', '.svg', '.bmp', '.tiff']

def resize_image(self, src, dst, max_size, bigger_panoramas=True):
def resize_image(self, src, dst, max_size, bigger_panoramas=True, preserve_exif_data=False):
"""Make a copy of the image in the requested size."""
if not Image or os.path.splitext(src)[1] in ['.svg', '.svgz']:
self.resize_svg(src, dst, max_size, bigger_panoramas)
@@ -70,6 +70,7 @@ def resize_image(self, src, dst, max_size, bigger_panoramas=True):
exif = im._getexif()
except Exception:
exif = None
_exif = im.info.get('exif')
if exif is not None:
for tag, value in list(exif.items()):
decoded = ExifTags.TAGS.get(tag, tag)
@@ -84,7 +85,10 @@ def resize_image(self, src, dst, max_size, bigger_panoramas=True):
break
try:
im.thumbnail(size, Image.ANTIALIAS)
im.save(dst)
if _exif is not None and preserve_exif_data:
im.save(dst, exif=_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))
@@ -454,6 +454,7 @@ def __init__(self, **config):
'POSTS_SECTION_FROM_META': False,
'POSTS_SECTION_NAME': "",
'POSTS_SECTION_TITLE': "{name}",
'PRESERVE_EXIF_DATA': False,
'PAGES': (("stories/*.txt", "stories", "story.tmpl"),),
'PANDOC_OPTIONS': [],
'PRETTY_URLS': False,
@@ -86,6 +86,7 @@ def set_site(self, site):
'tzinfo': site.tzinfo,
'comments_in_galleries': site.config['COMMENTS_IN_GALLERIES'],
'generate_rss': site.config['GENERATE_RSS'],
'preserve_exif_data': site.config['PRESERVE_EXIF_DATA'],
}

# Verify that no folder in GALLERY_FOLDERS appears twice
@@ -473,7 +474,7 @@ def create_target_images(self, img, input_path):
'targets': [thumb_path],
'actions': [
(self.resize_image,
(img, thumb_path, self.kw['thumbnail_size']))
(img, thumb_path, self.kw['thumbnail_size'], False, self.kw['preserve_exif_data']))
],
'clean': True,
'uptodate': [utils.config_changed({
@@ -488,7 +489,7 @@ def create_target_images(self, img, input_path):
'targets': [orig_dest_path],
'actions': [
(self.resize_image,
(img, orig_dest_path, self.kw['max_image_size']))
(img, orig_dest_path, self.kw['max_image_size'], False, self.kw['preserve_exif_data']))
],
'clean': True,
'uptodate': [utils.config_changed({
@@ -71,8 +71,8 @@ def process_tree(self, src, dst):

def process_image(self, src, dst, thumb):
"""Resize an image."""
self.resize_image(src, dst, self.kw['max_image_size'], False)
self.resize_image(src, thumb, self.kw['image_thumbnail_size'], False)
self.resize_image(src, dst, self.kw['max_image_size'], False, preserve_exif_data=self.kw['preserve_exif_data'])
self.resize_image(src, thumb, self.kw['image_thumbnail_size'], False, preserve_exif_data=self.kw['preserve_exif_data'])

def gen_tasks(self):
"""Copy static files into the output folder."""
@@ -82,6 +82,7 @@ def gen_tasks(self):
'image_folders': self.site.config['IMAGE_FOLDERS'],
'output_folder': self.site.config['OUTPUT_FOLDER'],
'filters': self.site.config['FILTERS'],
'preserve_exif_data': self.site.config['PRESERVE_EXIF_DATA'],
}

self.image_ext_list = self.image_ext_list_builtin

0 comments on commit e509a52

Please sign in to comment.