mirror of
https://github.com/Hopiu/wagtail.git
synced 2026-04-27 10:04:49 +00:00
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:
parent
42506e6fd8
commit
ee24881e71
3 changed files with 8 additions and 7 deletions
|
|
@ -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':
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue