Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: getnikola/nikola
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 402a62eee125
Choose a base ref
...
head repository: getnikola/nikola
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 6fd72bc23cd7
Choose a head ref
  • 7 commits
  • 4 files changed
  • 2 contributors

Commits on Sep 18, 2015

  1. Copy the full SHA
    71171b6 View commit details
  2. Fix #2094 - refinement

    TyberiusPrime committed Sep 18, 2015
    Copy the full SHA
    09ac576 View commit details
  3. Fix #2094 - docstrings

    TyberiusPrime committed Sep 18, 2015
    Copy the full SHA
    4afcab2 View commit details
  4. flake8

    TyberiusPrime committed Sep 18, 2015
    Copy the full SHA
    4d51022 View commit details
  5. pep257

    TyberiusPrime committed Sep 18, 2015
    Copy the full SHA
    47a2797 View commit details

Commits on Sep 21, 2015

  1. merge preparation

    TyberiusPrime committed Sep 21, 2015
    Copy the full SHA
    0033bb3 View commit details
  2. Merge pull request #2101 from TyberiusPrime/master

    Fix #2094 - scaling and colorbox of SVG thumbnails
    ralsina committed Sep 21, 2015
    Copy the full SHA
    6fd72bc View commit details
Showing with 53 additions and 2 deletions.
  1. +1 −0 AUTHORS.txt
  2. +1 −0 CHANGES.txt
  3. +46 −1 nikola/image_processing.py
  4. +5 −1 nikola/plugins/compile/rest/thumbnail.py
1 change: 1 addition & 0 deletions AUTHORS.txt
Original file line number Diff line number Diff line change
@@ -106,3 +106,4 @@
* `yarko <https://github.com/yarko>`_
* `小明 <https://github.com/dongweiming>`_
* `Brad Miller <https://github.com/bnmnetp>`_
* `Florian Finkernagel <https://github.com/TyberiusPrime>`_
1 change: 1 addition & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@ Bugfixes
``FEED_READ_MORE_LINK``, and ``FEED_LINKS_APPEND_QUERY`` for both Atom
and RSS feeds. (Issue #2095)
* /robots.txt was never being built (Issue #2098)
* SVG thumbnails (Issue #2094)

New in v7.7.1
=============
47 changes: 46 additions & 1 deletion nikola/image_processing.py
Original file line number Diff line number Diff line change
@@ -29,6 +29,9 @@
from __future__ import unicode_literals
import datetime
import os
import lxml
import re
import gzip

from nikola import utils

@@ -53,7 +56,7 @@ class ImageProcessor(object):
def resize_image(self, src, dst, max_size, bigger_panoramas=True):
"""Make a copy of the image in the requested size."""
if not Image or os.path.splitext(src)[1] in ['.svg', '.svgz']:
utils.copy_file(src, dst)
self.resize_svg(src, dst, max_size, bigger_panoramas)
return
im = Image.open(src)
w, h = im.size
@@ -90,6 +93,48 @@ def resize_image(self, src, dst, max_size, bigger_panoramas=True):
else: # Image is small
utils.copy_file(src, dst)

def resize_svg(self, src, dst, max_size, bigger_panoramas):
"""Make a copy of an svg at the requested size."""
try:
# 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:
xml = op.read()
else:
with open(src) as op:
xml = op.read()
tree = lxml.etree.XML(xml)
width = tree.attrib['width']
height = tree.attrib['height']
w = int(re.search("[0-9]+", width).group(0))
h = int(re.search("[0-9]+", height).group(0))
# calculate new size preserving aspect ratio.
ratio = float(w) / h
# Panoramas get larger thumbnails because they look *awful*
if bigger_panoramas and w > 2 * h:
max_size = max_size * 4
if w > h:
w = max_size
h = max_size / ratio
else:
w = max_size * ratio
h = max_size
w = int(w)
h = int(h)
tree.attrib.pop("width")
tree.attrib.pop("height")
tree.attrib['viewport'] = "0 0 %ipx %ipx" % (w, h)
if dst.endswith('.svgz'):
op = gzip.GzipFile(dst, 'w')
else:
op = open(dst, 'w')
op.write(lxml.etree.tostring(tree))
op.close()
except (KeyError, AttributeError) as e:
self.logger.warn("No width/height in %s. Actuall exception: %s" % (src, e))
utils.copy_file(src, dst)

def image_date(self, src):
"""Try to figure out the date of the image."""
if src not in self.dates:
6 changes: 5 additions & 1 deletion nikola/plugins/compile/rest/thumbnail.py
Original file line number Diff line number Diff line change
@@ -70,8 +70,12 @@ def figwidth_value(argument):
def run(self):
"""Run the thumbnail directive."""
uri = directives.uri(self.arguments[0])
if uri.endswith('.svg'):
# the ? at the end makes docutil output an <img> instead of an object for the svg, which colorbox requires
self.arguments[0] = '.thumbnail'.join(os.path.splitext(uri)) + '?'
else:
self.arguments[0] = '.thumbnail'.join(os.path.splitext(uri))
self.options['target'] = uri
self.arguments[0] = '.thumbnail'.join(os.path.splitext(uri))
if self.content:
(node,) = Figure.run(self)
else: