Create Thumbnail spec; closes #175

This commit is contained in:
Matthew Tretter 2012-12-06 23:48:09 -05:00
parent 1fb1d83c56
commit c69c2d087e
3 changed files with 17 additions and 0 deletions

View file

@ -1,6 +1,7 @@
# flake8: noqa
from . import conf
from . import generatorlibrary
from .specs import ImageSpec
from .pkgmeta import *
from .registry import register, unregister

View file

@ -0,0 +1,13 @@
from .registry import register
from .processors import Thumbnail as ThumbnailProcessor
from .specs import ImageSpec
class Thumbnail(ImageSpec):
def __init__(self, width=None, height=None, anchor='auto', crop=True, **kwargs):
self.processors = [ThumbnailProcessor(width, height, anchor=anchor,
crop=crop)]
super(Thumbnail, self).__init__(**kwargs)
register.spec('ik:thumbnail', Thumbnail)

View file

@ -235,6 +235,9 @@ class Thumbnail(object):
def process(self, img):
if self.crop:
if not self.width or not self.height:
raise Exception('You must provide both a width and height when'
' cropping.')
if self.anchor == 'auto':
processor = SmartResize(self.width, self.height)
else: