kopia lustrzana https://github.com/wagtail/wagtail
Made image processing code focal point aware
rodzic
c66180a9d9
commit
ee6f079f17
|
@ -98,7 +98,9 @@ class AbstractImage(models.Model, TagSearchable):
|
|||
|
||||
return focal_point
|
||||
|
||||
def get_rendition(self, filter):
|
||||
def get_rendition(self, filter, focal_point=None):
|
||||
focal_point = focal_point or self.focal_point
|
||||
|
||||
if not hasattr(filter, 'process_image'):
|
||||
# assume we've been passed a filter spec string, rather than a Filter object
|
||||
# TODO: keep an in-memory cache of filters, to avoid a db lookup
|
||||
|
@ -121,7 +123,7 @@ class AbstractImage(models.Model, TagSearchable):
|
|||
# If we have a backend attribute then pass it to process
|
||||
# image - else pass 'default'
|
||||
backend_name = getattr(self, 'backend', 'default')
|
||||
generated_image_file = filter.process_image(file_field.file, backend_name=backend_name)
|
||||
generated_image_file = filter.process_image(file_field.file, focal_point=focal_point, backend_name=backend_name)
|
||||
|
||||
if focal_point:
|
||||
rendition, created = self.renditions.get_or_create(
|
||||
|
@ -248,7 +250,7 @@ class Filter(models.Model):
|
|||
# Spec is not one of our recognised patterns
|
||||
raise ValueError("Invalid image filter spec: %r" % self.spec)
|
||||
|
||||
def process_image(self, input_file, backend_name='default'):
|
||||
def process_image(self, input_file, focal_point=None, backend_name='default'):
|
||||
"""
|
||||
Given an input image file as a django.core.files.File object,
|
||||
generate an output image with this filter applied, returning it
|
||||
|
@ -266,7 +268,7 @@ class Filter(models.Model):
|
|||
|
||||
method = getattr(backend, self.method_name)
|
||||
|
||||
image = method(image, self.method_arg)
|
||||
image = method(image, self.method_arg, focal_point=focal_point)
|
||||
|
||||
output = BytesIO()
|
||||
backend.save_image(image, output, file_format)
|
||||
|
|
Ładowanie…
Reference in New Issue