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 support for Django 2.1 (Ryan Verner, Matt Westcott)
|
||||||
|
* Added 'scale' image filter (Oliver Wilkerson)
|
||||||
|
|
||||||
|
|
||||||
2.2 (xx.xx.xxx) - IN DEVELOPMENT
|
2.2 (xx.xx.xxx) - IN DEVELOPMENT
|
||||||
|
|
|
@ -312,6 +312,7 @@ Contributors
|
||||||
* Aram Dulyan
|
* Aram Dulyan
|
||||||
* Kevin Howbrook
|
* Kevin Howbrook
|
||||||
* Ryan Verner
|
* Ryan Verner
|
||||||
|
* Oliver Wilkerson
|
||||||
|
|
||||||
Translators
|
Translators
|
||||||
===========
|
===========
|
||||||
|
|
|
@ -22,6 +22,9 @@ Wagtail is now compatible with Django 2.1. Compatibility fixes were contributed
|
||||||
Other features
|
Other features
|
||||||
~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
* Added 'scale' image filter (Oliver Wilkerson)
|
||||||
|
|
||||||
|
|
||||||
Bug fixes
|
Bug fixes
|
||||||
~~~~~~~~~
|
~~~~~~~~~
|
||||||
|
|
||||||
|
|
|
@ -88,6 +88,15 @@ The available resizing methods are as follows:
|
||||||
|
|
||||||
Resize the height of the image to the dimension specified.
|
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``
|
``fill``
|
||||||
(takes two dimensions and an optional ``-c`` parameter)
|
(takes two dimensions and an optional ``-c`` parameter)
|
||||||
|
|
||||||
|
|
|
@ -217,6 +217,20 @@ class WidthHeightOperation(Operation):
|
||||||
return willow.resize((width, height))
|
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):
|
class JPEGQualityOperation(Operation):
|
||||||
def construct(self, quality):
|
def construct(self, quality):
|
||||||
self.quality = int(quality)
|
self.quality = int(quality)
|
||||||
|
|
|
@ -362,6 +362,40 @@ class TestWidthHeightOperation(ImageOperationTestCase):
|
||||||
TestWidthHeightOperation.setup_test_methods()
|
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):
|
class TestCacheKey(TestCase):
|
||||||
def test_cache_key(self):
|
def test_cache_key(self):
|
||||||
image = Image(width=1000, height=1000)
|
image = Image(width=1000, height=1000)
|
||||||
|
|
|
@ -113,6 +113,7 @@ def register_image_operations():
|
||||||
('max', image_operations.MinMaxOperation),
|
('max', image_operations.MinMaxOperation),
|
||||||
('width', image_operations.WidthHeightOperation),
|
('width', image_operations.WidthHeightOperation),
|
||||||
('height', image_operations.WidthHeightOperation),
|
('height', image_operations.WidthHeightOperation),
|
||||||
|
('scale', image_operations.ScaleOperation),
|
||||||
('jpegquality', image_operations.JPEGQualityOperation),
|
('jpegquality', image_operations.JPEGQualityOperation),
|
||||||
('format', image_operations.FormatOperation),
|
('format', image_operations.FormatOperation),
|
||||||
('bgcolor', image_operations.BackgroundColorOperation),
|
('bgcolor', image_operations.BackgroundColorOperation),
|
||||||
|
|
Ładowanie…
Reference in New Issue