mirror of
https://github.com/Hopiu/django-imagekit.git
synced 2026-04-19 20:50:59 +00:00
Extracted ProcessorPipeline
Pulled some functionality out of _ImageSpecMixin into the ProcessorPipeline class so it could be used independently of the model-related stuff.
This commit is contained in:
parent
e190e78df5
commit
15e49be719
2 changed files with 17 additions and 6 deletions
|
|
@ -3,6 +3,7 @@ import datetime
|
|||
from StringIO import StringIO
|
||||
from imagekit.lib import *
|
||||
from imagekit.utils import img_to_fobj, get_spec_files
|
||||
from imagekit.processors import ProcessorPipeline
|
||||
from django.conf import settings
|
||||
from django.core.files.base import ContentFile
|
||||
from django.utils.encoding import force_unicode, smart_str
|
||||
|
|
@ -18,7 +19,6 @@ ImageFile.MAXBLOCK = getattr(settings, 'PIL_IMAGEFILE_MAXBLOCK', 256 * 2 ** 10)
|
|||
|
||||
|
||||
class _ImageSpecMixin(object):
|
||||
|
||||
def __init__(self, processors=None, quality=70, format=None):
|
||||
self.processors = processors
|
||||
self.quality = quality
|
||||
|
|
@ -27,11 +27,9 @@ class _ImageSpecMixin(object):
|
|||
def process(self, image, file):
|
||||
fmt = image.format
|
||||
img = image.copy()
|
||||
for proc in self.processors:
|
||||
img, fmt = proc.process(img, fmt, file)
|
||||
format = self.format or fmt
|
||||
img.format = format
|
||||
return img, format
|
||||
processors = ProcessorPipeline(self.processors)
|
||||
img, fmt = processors.process(img, fmt, file)
|
||||
return img, self.format or fmt
|
||||
|
||||
|
||||
class ImageSpec(_ImageSpecMixin):
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ own effects/processes entirely.
|
|||
"""
|
||||
from imagekit.lib import *
|
||||
|
||||
|
||||
class ImageProcessor(object):
|
||||
""" Base image processor class """
|
||||
|
||||
|
|
@ -15,6 +16,18 @@ class ImageProcessor(object):
|
|||
return img, fmt
|
||||
|
||||
|
||||
class ProcessorPipeline(ImageProcessor, list):
|
||||
"""A processor that just runs a bunch of other processors. This class allows
|
||||
any object that knows how to deal with a single processor to deal with a
|
||||
list of them.
|
||||
|
||||
"""
|
||||
def process(self, img, fmt, file):
|
||||
for proc in self:
|
||||
img, fmt = proc.process(img, fmt, file)
|
||||
return img, fmt
|
||||
|
||||
|
||||
class Adjust(ImageProcessor):
|
||||
|
||||
def __init__(self, color=1.0, brightness=1.0, contrast=1.0, sharpness=1.0):
|
||||
|
|
|
|||
Loading…
Reference in a new issue