Skip to content

Commit

Permalink
Use bytes for .svg(z) files in thumbnail generation
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
  • Loading branch information
Kwpolska committed Mar 18, 2016
1 parent d1f0c18 commit a3e05ca
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
12 changes: 12 additions & 0 deletions CHANGES.txt
@@ -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
=============

Expand Down
10 changes: 5 additions & 5 deletions nikola/image_processing.py
Expand Up @@ -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."""
Expand Down Expand Up @@ -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']
Expand All @@ -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:
Expand Down

0 comments on commit a3e05ca

Please sign in to comment.