0
0
mirror of https://github.com/wagtail/wagtail.git synced 2024-12-01 11:41:20 +01:00

Added get_vary and get_vary_key to Filter

This allows a filter operation to specify which strings of data it used
inside the image to perform its calculations. This can be used to
determine whether an image has changed in such a way that requires new
renditions to be made.
This commit is contained in:
Karl Hobley 2014-11-03 13:37:30 +00:00 committed by Karl Hobley
parent 2662866719
commit 19309b02e7
2 changed files with 32 additions and 0 deletions

View File

@ -147,6 +147,21 @@ class FillOperation(object):
willow.resize(width, height)
def get_vary(self, image):
focal_point = image.get_focal_point()
if focal_point is not None:
focal_point_key = "%(x)d-%(y)d-%(width)dx%(height)d" % {
'x': int(focal_point.centroid_x),
'y': int(focal_point.centroid_y),
'width': int(focal_point.width),
'height': int(focal_point.height),
}
else:
focal_point_key = ''
return [focal_point_key]
class MinMaxOperation(object):
def __init__(self, method, size):

View File

@ -1,4 +1,5 @@
import os.path
import hashlib
import re
from six import BytesIO, text_type
@ -428,6 +429,22 @@ class Filter(models.Model):
return output
def get_vary(self, image):
vary = []
for operation in self.operations:
if hasattr(operation, 'get_vary'):
vary.extend(operation.get_vary(image))
return vary
def get_vary_key(self, image):
vary_string = '-'.join(self.get_vary(image))
vary_key = hashlib.sha1(vary_string.encode('utf-8')).hexdigest()
return vary_key[:8]
_registered_operations = None
@classmethod