Skip to content
Permalink
Browse files
Use bytes for .svg(z) files in thumbnail generation
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
  • Loading branch information
Kwpolska committed Mar 18, 2016
1 parent d1f0c18 commit a3e05ca343e8252a32632f783b10b7565f309b01
Showing with 17 additions and 5 deletions.
  1. +12 −0 CHANGES.txt
  2. +5 −5 nikola/image_processing.py
@@ -1,3 +1,15 @@
New in master
=============

Features
--------

Bugfixes
--------

* Use binary I/O for ``.svg`` files in galleries
* Accept ``.svgz`` extension by default

New in v7.7.7
=============

@@ -50,7 +50,7 @@
class ImageProcessor(object):
"""Apply image operations."""

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

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."""
@@ -102,10 +102,10 @@ def resize_svg(self, src, dst, max_size, bigger_panoramas):
# Resize svg based on viewport hacking.
# note that this can also lead to enlarged svgs
if src.endswith('.svgz'):
with gzip.GzipFile(src) as op:
with gzip.GzipFile(src, 'rb') as op:
xml = op.read()
else:
with open(src) as op:
with open(src, 'rb') as op:
xml = op.read()
tree = lxml.etree.XML(xml)
width = tree.attrib['width']
@@ -129,9 +129,9 @@ def resize_svg(self, src, dst, max_size, bigger_panoramas):
tree.attrib.pop("height")
tree.attrib['viewport'] = "0 0 %ipx %ipx" % (w, h)
if dst.endswith('.svgz'):
op = gzip.GzipFile(dst, 'w')
op = gzip.GzipFile(dst, 'wb')
else:
op = open(dst, 'w')
op = open(dst, 'wb')
op.write(lxml.etree.tostring(tree))
op.close()
except (KeyError, AttributeError) as e:

0 comments on commit a3e05ca

Please sign in to comment.