kopia lustrzana https://github.com/wagtail/wagtail
Added a simple scale filter to image_operations.
rodzic
12c0fe2556
commit
091ea75de7
|
@ -5,6 +5,7 @@ Changelog
|
|||
~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
* Added support for Django 2.1 (Ryan Verner, Matt Westcott)
|
||||
* Added 'scale' image filter (Oliver Wilkerson)
|
||||
|
||||
|
||||
2.2 (xx.xx.xxx) - IN DEVELOPMENT
|
||||
|
|
|
@ -312,6 +312,7 @@ Contributors
|
|||
* Aram Dulyan
|
||||
* Kevin Howbrook
|
||||
* Ryan Verner
|
||||
* Oliver Wilkerson
|
||||
|
||||
Translators
|
||||
===========
|
||||
|
|
|
@ -22,6 +22,9 @@ Wagtail is now compatible with Django 2.1. Compatibility fixes were contributed
|
|||
Other features
|
||||
~~~~~~~~~~~~~~
|
||||
|
||||
* Added 'scale' image filter (Oliver Wilkerson)
|
||||
|
||||
|
||||
Bug fixes
|
||||
~~~~~~~~~
|
||||
|
||||
|
|
|
@ -88,6 +88,15 @@ The available resizing methods are as follows:
|
|||
|
||||
Resize the height of the image to the dimension specified.
|
||||
|
||||
``scale``
|
||||
(takes percentage)
|
||||
|
||||
.. code-block:: html+django
|
||||
|
||||
{% image page.photo scale-50 %}
|
||||
|
||||
Resize the image to the percentage specified.
|
||||
|
||||
``fill``
|
||||
(takes two dimensions and an optional ``-c`` parameter)
|
||||
|
||||
|
|
|
@ -217,6 +217,20 @@ class WidthHeightOperation(Operation):
|
|||
return willow.resize((width, height))
|
||||
|
||||
|
||||
class ScaleOperation(Operation):
|
||||
def construct(self, percent):
|
||||
self.percent = float(percent)
|
||||
|
||||
def run(self, willow, image, env):
|
||||
image_width, image_height = willow.get_size()
|
||||
|
||||
scale = self.percent / 100
|
||||
width = float(image_width * scale)
|
||||
height = float(image_height * scale)
|
||||
|
||||
return willow.resize((width, height))
|
||||
|
||||
|
||||
class JPEGQualityOperation(Operation):
|
||||
def construct(self, quality):
|
||||
self.quality = int(quality)
|
||||
|
|
|
@ -362,6 +362,40 @@ class TestWidthHeightOperation(ImageOperationTestCase):
|
|||
TestWidthHeightOperation.setup_test_methods()
|
||||
|
||||
|
||||
class TestScaleOperation(ImageOperationTestCase):
|
||||
operation_class = image_operations.ScaleOperation
|
||||
|
||||
filter_spec_tests = [
|
||||
('scale-100', dict(method='scale', percent=100)),
|
||||
('scale-50', dict(method='scale', percent=50)),
|
||||
]
|
||||
|
||||
filter_spec_error_tests = [
|
||||
'scale',
|
||||
'scale-800x600',
|
||||
'scale-abc',
|
||||
'scale-800-c100',
|
||||
]
|
||||
|
||||
run_tests = [
|
||||
# Basic almost a no-op of scale
|
||||
('scale-100', dict(width=1000, height=500), [
|
||||
('resize', ((1000, 500), ), {}),
|
||||
]),
|
||||
# Basic usage of scale
|
||||
('scale-50', dict(width=1000, height=500), [
|
||||
('resize', ((500, 250), ), {}),
|
||||
]),
|
||||
# Rounded usage of scale
|
||||
('scale-83.0322', dict(width=1000, height=500), [
|
||||
('resize', ((1000 * 0.830322, 500 * 0.830322), ), {}),
|
||||
]),
|
||||
]
|
||||
|
||||
|
||||
TestScaleOperation.setup_test_methods()
|
||||
|
||||
|
||||
class TestCacheKey(TestCase):
|
||||
def test_cache_key(self):
|
||||
image = Image(width=1000, height=1000)
|
||||
|
|
|
@ -113,6 +113,7 @@ def register_image_operations():
|
|||
('max', image_operations.MinMaxOperation),
|
||||
('width', image_operations.WidthHeightOperation),
|
||||
('height', image_operations.WidthHeightOperation),
|
||||
('scale', image_operations.ScaleOperation),
|
||||
('jpegquality', image_operations.JPEGQualityOperation),
|
||||
('format', image_operations.FormatOperation),
|
||||
('bgcolor', image_operations.BackgroundColorOperation),
|
||||
|
|
Ładowanie…
Reference in New Issue