Added new env argument to ImageOperation.run

This is set to a mutable dictionary that is passed between the image operations. It can be used for image operations to send messages to later operations and Wagtail.
This commit is contained in:
Karl Hobley 2016-04-12 20:48:45 +01:00 committed by Matt Westcott
parent 42506e6fd8
commit ee24881e71
3 changed files with 8 additions and 7 deletions

View file

@ -26,7 +26,7 @@ class Operation(object):
def construct(self, *args):
raise NotImplementedError
def run(self, willow, image):
def run(self, willow, image, env):
raise NotImplementedError
@ -34,7 +34,7 @@ class DoNothingOperation(Operation):
def construct(self):
pass
def run(self, willow, image):
def run(self, willow, image, env):
pass
@ -63,7 +63,7 @@ class FillOperation(Operation):
if self.crop_closeness > 1:
self.crop_closeness = 1
def run(self, willow, image):
def run(self, willow, image, env):
image_width, image_height = willow.get_size()
focal_point = image.get_focal_point()
@ -151,7 +151,7 @@ class MinMaxOperation(Operation):
self.width = int(width_str)
self.height = int(height_str)
def run(self, willow, image):
def run(self, willow, image, env):
image_width, image_height = willow.get_size()
horz_scale = self.width / image_width
@ -190,7 +190,7 @@ class WidthHeightOperation(Operation):
def construct(self, size):
self.size = int(size)
def run(self, willow, image):
def run(self, willow, image, env):
image_width, image_height = willow.get_size()
if self.method == 'width':

View file

@ -410,8 +410,9 @@ class Filter(models.Model):
# Fix orientation of image
willow = willow.auto_orient()
env = {}
for operation in self.operations:
willow = operation.run(willow, image) or willow
willow = operation.run(willow, image, env) or willow
if original_format == 'jpeg':
# Allow changing of JPEG compression quality

View file

@ -81,7 +81,7 @@ class ImageOperationTestCase(TestCase):
operation_recorder = WillowOperationRecorder((image.width, image.height))
# Run
operation.run(operation_recorder, image)
operation.run(operation_recorder, image, {})
# Check
self.assertEqual(operation_recorder.ran_operations, expected_output)