Skip to content

Commit

Permalink
Added Image.evaluate_images method
Browse files Browse the repository at this point in the history
  • Loading branch information
emcconville committed Nov 25, 2023
1 parent 1630615 commit 1154504
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
18 changes: 17 additions & 1 deletion docs/changes.rst
Original file line number Diff line number Diff line change
@@ -1,13 +1,29 @@
Wand Changelog
==============

.. _changelog-0.7:

0.7 series
~~~~~~~~~~


.. _changelog-0.7.0:

Version 0.7.0
-------------

Unreleased.

- Added :meth:`Image.evaluate_images() <wand.image.BaseImage.evaluate_images>` method.


.. _changelog-0.6:

0.6 series
~~~~~~~~~~


.. _changelog-0.6.12:
.. _changelog-0.6.13:

Version 0.6.13
--------------
Expand Down
8 changes: 8 additions & 0 deletions tests/image_methods_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,14 @@ def test_evaluate_user_error():
img.evaluate(operator='set', value=1.0, channel='Not a channel')


def test_evaluate_images():
with Image(filename='hald:3') as img:
with img.clone() as i:
img.image_add(i)
with img.evaluate_images(operator='add') as nue:
assert nue != img


def test_export_pixels():
with Image(filename='hald:2') as img:
img.depth = 8 # Not need, but want to match import.
Expand Down
26 changes: 26 additions & 0 deletions wand/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -4869,6 +4869,32 @@ def evaluate(self, operator=None, value=0.0, channel=None):
library.MagickSetImageChannelMask(self.wand, channel_mask)
return r

def evaluate_images(self, operator=None):
"""Create a new image by applying arithmetic operation between all
images loaded in the image-stack.
For example::
with Image() as img:
img.read(filename='first.png')
img.read(filename='second.png')
first.evaluate_images('add')
first.save(filename='sum.png')
:param operator: Type of operation to calculate.
:type operator: :const:`EVALUATE_OPS`
.. versionadded:: 0.7.0
"""
assertions.string_in_list(EVALUATE_OPS, 'wand.image.EVALUATE_OPS',
operator=operator)
self.iterator_reset()
idx_op = EVALUATE_OPS.index(operator)
result = library.MagickEvaluateImages(self.wand, idx_op)
if not result:
self.raise_exception()
return Image(image=BaseImage(result))

def export_pixels(self, x=0, y=0, width=None, height=None,
channel_map="RGBA", storage='char'):
"""Export pixel data from a raster image to
Expand Down

0 comments on commit 1154504

Please sign in to comment.