diff --git a/imagekit/__init__.py b/imagekit/__init__.py index 2c72bf4..e65c270 100644 --- a/imagekit/__init__.py +++ b/imagekit/__init__.py @@ -1,6 +1,7 @@ # flake8: noqa from . import conf +from . import generatorlibrary from .specs import ImageSpec from .pkgmeta import * from .registry import register, unregister diff --git a/imagekit/generatorlibrary.py b/imagekit/generatorlibrary.py new file mode 100644 index 0000000..1786022 --- /dev/null +++ b/imagekit/generatorlibrary.py @@ -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) diff --git a/imagekit/processors/resize.py b/imagekit/processors/resize.py index 624ccf6..f241ca6 100644 --- a/imagekit/processors/resize.py +++ b/imagekit/processors/resize.py @@ -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: