mirror of
https://github.com/Hopiu/django-imagekit.git
synced 2026-03-17 05:40:25 +00:00
Create Thumbnail spec; closes #175
This commit is contained in:
parent
1fb1d83c56
commit
c69c2d087e
3 changed files with 17 additions and 0 deletions
|
|
@ -1,6 +1,7 @@
|
|||
# flake8: noqa
|
||||
|
||||
from . import conf
|
||||
from . import generatorlibrary
|
||||
from .specs import ImageSpec
|
||||
from .pkgmeta import *
|
||||
from .registry import register, unregister
|
||||
|
|
|
|||
13
imagekit/generatorlibrary.py
Normal file
13
imagekit/generatorlibrary.py
Normal 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)
|
||||
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Reference in a new issue