From 690cf9ebe2d7002eb134980cbb07ed7b113ae5bb Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sat, 6 Mar 2021 20:54:21 +1100 Subject: [PATCH 1/2] Allow alpha_composite destination to be negative --- Tests/test_image.py | 8 ++++++-- src/PIL/Image.py | 2 -- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Tests/test_image.py b/Tests/test_image.py index 73cf7bf83..de1999d3d 100644 --- a/Tests/test_image.py +++ b/Tests/test_image.py @@ -344,6 +344,12 @@ class TestImage: assert_image_equal(offset.crop((64, 64, 127, 127)), target.crop((0, 0, 63, 63))) assert offset.size == (128, 128) + # with negative offset + offset = src.copy() + offset.alpha_composite(over, (-64, -64)) + assert_image_equal(offset.crop((0, 0, 63, 63)), target.crop((64, 64, 127, 127))) + assert offset.size == (128, 128) + # offset and crop box = src.copy() box.alpha_composite(over, (64, 64), (0, 0, 32, 32)) @@ -367,8 +373,6 @@ class TestImage: source.alpha_composite(over, 0) with pytest.raises(ValueError): source.alpha_composite(over, (0, 0), 0) - with pytest.raises(ValueError): - source.alpha_composite(over, (0, -1)) with pytest.raises(ValueError): source.alpha_composite(over, (0, 0), (0, -1)) diff --git a/src/PIL/Image.py b/src/PIL/Image.py index 01fe7ed1b..d2a7c3490 100644 --- a/src/PIL/Image.py +++ b/src/PIL/Image.py @@ -1544,8 +1544,6 @@ class Image: raise ValueError("Destination must be a 2-tuple") if min(source) < 0: raise ValueError("Source must be non-negative") - if min(dest) < 0: - raise ValueError("Destination must be non-negative") if len(source) == 2: source = source + im.size From 45c43fc9112e08b050fe5322399500c60fef2d90 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Mon, 8 Mar 2021 19:39:28 +1100 Subject: [PATCH 2/2] Added release notes [ci skip] --- docs/releasenotes/8.2.0.rst | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/docs/releasenotes/8.2.0.rst b/docs/releasenotes/8.2.0.rst index 28d39ca46..92909cfb5 100644 --- a/docs/releasenotes/8.2.0.rst +++ b/docs/releasenotes/8.2.0.rst @@ -13,10 +13,13 @@ when Tk/Tcl 8.5 will be the minimum supported. API Changes =========== -TODO -^^^^ +Image.alpha_composite: dest +^^^^^^^^^^^^^^^^^^^^^^^^^^^ -TODO +When calling :py:meth:`~PIL.Image.Image.alpha_composite`, the ``dest`` argument now +accepts negative co-ordinates, like the upper left corner of the ``box`` argument of +:py:meth:`~PIL.Image.Image.paste` can be negative. Naturally, this has effect of +cropping the overlaid image. API Additions =============