Browse Source

Add support for using pillow instead of PIL.

main
Lakshmi Vyasarajan 11 years ago
parent
commit
6472c74928
3 changed files with 16 additions and 9 deletions
  1. +1
    -1
      dev-req.txt
  2. +8
    -4
      hyde/ext/plugins/images.py
  3. +7
    -4
      hyde/tests/ext/test_images.py

+ 1
- 1
dev-req.txt View File

@@ -3,4 +3,4 @@ pyquery
docutils docutils
mock mock
nose nose
PIL
pillow

+ 8
- 4
hyde/ext/plugins/images.py View File

@@ -2,17 +2,21 @@
""" """
Contains classes to handle images related things Contains classes to handle images related things


# Requires PIL
# Requires PIL or pillow
""" """


from hyde.plugin import Plugin from hyde.plugin import Plugin
from hyde.fs import File, Folder


import re import re
import Image
import glob import glob
import os import os


try:
from PIL import Image
except ImportError:
# No pillow
import Image

class ImageSizerPlugin(Plugin): class ImageSizerPlugin(Plugin):
""" """
Each HTML page is modified to add width and height for images if Each HTML page is modified to add width and height for images if
@@ -239,7 +243,7 @@ class ImageThumbnailsPlugin(Plugin):
path = os.path.join(".thumbnails", path = os.path.join(".thumbnails",
os.path.dirname(resource.get_relative_deploy_path()), os.path.dirname(resource.get_relative_deploy_path()),
"%s%s" % (prefix, name)) "%s%s" % (prefix, name))
target = File(Folder(resource.site.config.content_root_path).child(path))
target = resource.site.config.content_root_path.child_file(path)
res = self.site.content.add_resource(target) res = self.site.content.add_resource(target)
res.set_relative_deploy_path(res.get_relative_deploy_path().replace('.thumbnails/', '', 1)) res.set_relative_deploy_path(res.get_relative_deploy_path().replace('.thumbnails/', '', 1))




+ 7
- 4
hyde/tests/ext/test_images.py View File

@@ -26,7 +26,11 @@ IMAGES = [PORTRAIT_IMAGE, LANDSCAPE_IMAGE]
SIZES = [PORTRAIT_SIZE, LANDSCAPE_SIZE] SIZES = [PORTRAIT_SIZE, LANDSCAPE_SIZE]


# PIL requirement # PIL requirement
import Image
try:
from PIL import Image
except ImportError:
# No pillow
import Image


class TestImageSizer(object): class TestImageSizer(object):


@@ -91,12 +95,11 @@ class TestImageSizer(object):
text = u""" text = u"""
<img src="/media/img/hyde-logo-no.png"> <img src="/media/img/hyde-logo-no.png">
""" """
html = self._generic_test_image(text)
self._generic_test_image(text)


def test_size_image_multiline(self): def test_size_image_multiline(self):
text = u""" text = u"""
<img
src="/media/img/%s">
<img src="/media/img/%s">
""" % PORTRAIT_IMAGE """ % PORTRAIT_IMAGE
html = self._generic_test_image(text) html = self._generic_test_image(text)
assert ' width="%d"' % PORTRAIT_SIZE[0] in html assert ' width="%d"' % PORTRAIT_SIZE[0] in html


Loading…
Cancel
Save