From 1154504f60fe374392436732f017f5658dddede2 Mon Sep 17 00:00:00 2001 From: "E. McConville" Date: Fri, 24 Nov 2023 20:48:16 -0600 Subject: [PATCH] Added Image.evaluate_images method --- docs/changes.rst | 18 +++++++++++++++++- tests/image_methods_test.py | 8 ++++++++ wand/image.py | 26 ++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 1 deletion(-) diff --git a/docs/changes.rst b/docs/changes.rst index 0ebcc326..8af387ad 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -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() ` method. + + .. _changelog-0.6: 0.6 series ~~~~~~~~~~ -.. _changelog-0.6.12: +.. _changelog-0.6.13: Version 0.6.13 -------------- diff --git a/tests/image_methods_test.py b/tests/image_methods_test.py index c5dfda09..ce41b64f 100644 --- a/tests/image_methods_test.py +++ b/tests/image_methods_test.py @@ -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. diff --git a/wand/image.py b/wand/image.py index b721588b..c5819b54 100644 --- a/wand/image.py +++ b/wand/image.py @@ -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