Skip to content

Commit

Permalink
Merge pull request #5313 from radarhere/alpha_composite
Browse files Browse the repository at this point in the history
Allow alpha_composite destination to be negative
  • Loading branch information
mergify[bot] committed Mar 8, 2021
2 parents 7c7a688 + 3225e39 commit e110e09
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
8 changes: 6 additions & 2 deletions Tests/test_image.py
Expand Up @@ -344,6 +344,12 @@ def test_alpha_inplace(self):
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))
Expand All @@ -367,8 +373,6 @@ def test_alpha_inplace(self):
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))

Expand Down
8 changes: 8 additions & 0 deletions docs/releasenotes/8.2.0.rst
Expand Up @@ -13,6 +13,14 @@ when Tk/Tcl 8.5 will be the minimum supported.
API Changes
===========

Image.alpha_composite: dest
^^^^^^^^^^^^^^^^^^^^^^^^^^^

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.

ImageDraw.rounded_rectangle
^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand Down
2 changes: 0 additions & 2 deletions src/PIL/Image.py
Expand Up @@ -1544,8 +1544,6 @@ def alpha_composite(self, im, dest=(0, 0), source=(0, 0)):
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
Expand Down

0 comments on commit e110e09

Please sign in to comment.