mirror of
				https://github.com/python-pillow/Pillow.git
				synced 2025-11-04 09:57:43 +03:00 
			
		
		
		
	Merge pull request #5313 from radarhere/alpha_composite
Allow alpha_composite destination to be negative
This commit is contained in:
		
						commit
						e110e093a6
					
				| 
						 | 
					@ -344,6 +344,12 @@ class TestImage:
 | 
				
			||||||
        assert_image_equal(offset.crop((64, 64, 127, 127)), target.crop((0, 0, 63, 63)))
 | 
					        assert_image_equal(offset.crop((64, 64, 127, 127)), target.crop((0, 0, 63, 63)))
 | 
				
			||||||
        assert offset.size == (128, 128)
 | 
					        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
 | 
					        # offset and crop
 | 
				
			||||||
        box = src.copy()
 | 
					        box = src.copy()
 | 
				
			||||||
        box.alpha_composite(over, (64, 64), (0, 0, 32, 32))
 | 
					        box.alpha_composite(over, (64, 64), (0, 0, 32, 32))
 | 
				
			||||||
| 
						 | 
					@ -367,8 +373,6 @@ class TestImage:
 | 
				
			||||||
            source.alpha_composite(over, 0)
 | 
					            source.alpha_composite(over, 0)
 | 
				
			||||||
        with pytest.raises(ValueError):
 | 
					        with pytest.raises(ValueError):
 | 
				
			||||||
            source.alpha_composite(over, (0, 0), 0)
 | 
					            source.alpha_composite(over, (0, 0), 0)
 | 
				
			||||||
        with pytest.raises(ValueError):
 | 
					 | 
				
			||||||
            source.alpha_composite(over, (0, -1))
 | 
					 | 
				
			||||||
        with pytest.raises(ValueError):
 | 
					        with pytest.raises(ValueError):
 | 
				
			||||||
            source.alpha_composite(over, (0, 0), (0, -1))
 | 
					            source.alpha_composite(over, (0, 0), (0, -1))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -13,6 +13,14 @@ when Tk/Tcl 8.5 will be the minimum supported.
 | 
				
			||||||
API Changes
 | 
					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
 | 
					ImageDraw.rounded_rectangle
 | 
				
			||||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^
 | 
					^^^^^^^^^^^^^^^^^^^^^^^^^^^
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1544,8 +1544,6 @@ class Image:
 | 
				
			||||||
            raise ValueError("Destination must be a 2-tuple")
 | 
					            raise ValueError("Destination must be a 2-tuple")
 | 
				
			||||||
        if min(source) < 0:
 | 
					        if min(source) < 0:
 | 
				
			||||||
            raise ValueError("Source must be non-negative")
 | 
					            raise ValueError("Source must be non-negative")
 | 
				
			||||||
        if min(dest) < 0:
 | 
					 | 
				
			||||||
            raise ValueError("Destination must be non-negative")
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if len(source) == 2:
 | 
					        if len(source) == 2:
 | 
				
			||||||
            source = source + im.size
 | 
					            source = source + im.size
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user