kopia lustrzana https://github.com/wagtail/wagtail
Willow 0.3 support
rodzic
fb50eb0d7e
commit
1565e74101
2
setup.py
2
setup.py
|
@ -30,7 +30,7 @@ install_requires = [
|
|||
"beautifulsoup4>=4.3.2",
|
||||
"html5lib>=0.999,<1",
|
||||
"Unidecode>=0.04.14",
|
||||
"Willow>=0.2.2,<0.3",
|
||||
"Willow>=0.3,<0.4",
|
||||
]
|
||||
|
||||
# Testing dependencies
|
||||
|
|
2
tox.ini
2
tox.ini
|
@ -33,7 +33,7 @@ deps =
|
|||
python-dateutil==2.2
|
||||
pytz==2014.7
|
||||
Embedly
|
||||
Willow==0.2
|
||||
Willow==0.3b4
|
||||
jinja2==2.8
|
||||
coverage
|
||||
|
||||
|
|
|
@ -128,7 +128,7 @@ class FillOperation(Operation):
|
|||
rect = rect.move_to_clamp(Rect(0, 0, image_width, image_height))
|
||||
|
||||
# Crop!
|
||||
willow.crop(rect.round())
|
||||
willow = willow.crop(rect.round())
|
||||
|
||||
# Get scale for resizing
|
||||
# The scale should be the same for both the horizontal and
|
||||
|
@ -139,7 +139,9 @@ class FillOperation(Operation):
|
|||
# Only resize if the image is too big
|
||||
if scale < 1.0:
|
||||
# Resize!
|
||||
willow.resize((self.width, self.height))
|
||||
willow = willow.resize((self.width, self.height))
|
||||
|
||||
return willow
|
||||
|
||||
|
||||
class MinMaxOperation(Operation):
|
||||
|
@ -181,7 +183,7 @@ class MinMaxOperation(Operation):
|
|||
# Unknown method
|
||||
return
|
||||
|
||||
willow.resize((width, height))
|
||||
return willow.resize((width, height))
|
||||
|
||||
|
||||
class WidthHeightOperation(Operation):
|
||||
|
@ -213,4 +215,4 @@ class WidthHeightOperation(Operation):
|
|||
# Unknown method
|
||||
return
|
||||
|
||||
willow.resize((width, height))
|
||||
return willow.resize((width, height))
|
||||
|
|
|
@ -382,12 +382,14 @@ class Filter(models.Model):
|
|||
|
||||
def run(self, image, output):
|
||||
with image.get_willow_image() as willow:
|
||||
original_format = willow.format_name
|
||||
|
||||
for operation in self.operations:
|
||||
operation.run(willow, image)
|
||||
willow = operation.run(willow, image) or willow
|
||||
|
||||
output_format = willow.original_format
|
||||
output_format = original_format
|
||||
|
||||
if willow.original_format == 'jpeg':
|
||||
if original_format == 'jpeg':
|
||||
# Allow changing of JPEG compression quality
|
||||
if hasattr(settings, 'WAGTAILIMAGES_JPEG_QUALITY'):
|
||||
quality = settings.WAGTAILIMAGES_JPEG_QUALITY
|
||||
|
@ -395,19 +397,19 @@ class Filter(models.Model):
|
|||
quality = 85
|
||||
|
||||
willow.save_as_jpeg(output, quality=quality)
|
||||
if willow.original_format == 'gif':
|
||||
elif original_format == 'gif':
|
||||
# Convert image to PNG if it's not animated
|
||||
if not willow.has_animation():
|
||||
output_format = 'png'
|
||||
willow.save_as_png(output)
|
||||
else:
|
||||
willow.save_as_gif(output)
|
||||
if willow.original_format == 'bmp':
|
||||
elif original_format == 'bmp':
|
||||
# Convert to PNG
|
||||
output_format = 'png'
|
||||
willow.save_as_png(output)
|
||||
else:
|
||||
willow.save(willow.original_format, output)
|
||||
willow.save(original_format, output)
|
||||
|
||||
return output, output_format
|
||||
|
||||
|
|
|
@ -14,6 +14,8 @@ class WillowOperationRecorder(object):
|
|||
This class pretends to be a Willow image but instead, it records
|
||||
the operations that have been performed on the image for testing
|
||||
"""
|
||||
format_name = 'jpeg'
|
||||
|
||||
def __init__(self, start_size):
|
||||
self.ran_operations = []
|
||||
self.start_size = start_size
|
||||
|
@ -21,6 +23,7 @@ class WillowOperationRecorder(object):
|
|||
def __getattr__(self, attr):
|
||||
def operation(*args, **kwargs):
|
||||
self.ran_operations.append((attr, args, kwargs))
|
||||
return self
|
||||
|
||||
return operation
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue