Skip to content
Permalink
Browse files
initial, totally untested, implementation
  • Loading branch information
ralsina committed Jul 18, 2016
1 parent cb0ab10 commit 794495ef9a8a7f060932fc20dafe70b19cb3f736
Showing with 34 additions and 0 deletions.
  1. +34 −0 nikola/image_processing.py
@@ -49,14 +49,48 @@
except ImportError:
pass

EXIF_TAG_NAMES = {}


class ImageProcessor(object):
"""Apply image operations."""

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

def _fill_exif_tag_names(self):
# Convert whitelisted tag names to numeric values
if not EXIF_TAG_NAMES:
for ifd in piexif.TAGS:
for tag, data in ifd.items():
EXIF_TAG_NAMES[tag] = data['name']

def filter_exif(self, exif, whitelist):
"""Filter EXIF data as described in the documentation."""

self._fill_exif_tag_names()
exif = exif.copy() # Don't modify in-place, it's rude

# Scenario 1: keep everything
if whitelist == {'*': '*'}:
return exif

# Scenario 2: keep nothing
if whitelist == {}:
return {}

# Scenario 3: keep some
for k in exif:
if k not in whitelist:
exif.pop(k) # Not whitelisted, remove
elif k in whitelist and whitelist[k] == '*':
# Fully whitelisted, keep all
pass
else:
# Partially whitelisted
for tag in exif[k]:
if EXIF_TAG_NAMES[tag] not in whitelist[k]:
exif[k].pop(tag)

return exif

def resize_image(self, src, dst, max_size, bigger_panoramas=True, preserve_exif_data=False, exif_whitelist={}):

0 comments on commit 794495e

Please sign in to comment.