2012-10-16 00:26:38 +04:00
|
|
|
from PIL import Image
|
|
|
|
|
2019-11-04 01:18:55 +03:00
|
|
|
from .helper import hopper
|
2019-07-06 23:40:53 +03:00
|
|
|
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2019-11-04 01:18:55 +03:00
|
|
|
def test_sanity():
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2019-11-04 01:18:55 +03:00
|
|
|
bbox = hopper().getbbox()
|
|
|
|
assert isinstance(bbox, tuple)
|
2012-10-16 00:26:38 +04:00
|
|
|
|
|
|
|
|
2019-11-04 01:18:55 +03:00
|
|
|
def test_bbox():
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2019-11-04 01:18:55 +03:00
|
|
|
# 8-bit mode
|
|
|
|
im = Image.new("L", (100, 100), 0)
|
|
|
|
assert im.getbbox() is None
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2019-11-04 01:18:55 +03:00
|
|
|
im.paste(255, (10, 25, 90, 75))
|
|
|
|
assert im.getbbox() == (10, 25, 90, 75)
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2019-11-04 01:18:55 +03:00
|
|
|
im.paste(255, (25, 10, 75, 90))
|
|
|
|
assert im.getbbox() == (10, 10, 90, 90)
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2019-11-04 01:18:55 +03:00
|
|
|
im.paste(255, (-10, -10, 110, 110))
|
|
|
|
assert im.getbbox() == (0, 0, 100, 100)
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2019-11-04 01:18:55 +03:00
|
|
|
# 32-bit mode
|
|
|
|
im = Image.new("RGB", (100, 100), 0)
|
|
|
|
assert im.getbbox() is None
|
2014-06-10 13:10:47 +04:00
|
|
|
|
2019-11-04 01:18:55 +03:00
|
|
|
im.paste(255, (10, 25, 90, 75))
|
|
|
|
assert im.getbbox() == (10, 25, 90, 75)
|
2014-06-10 13:10:47 +04:00
|
|
|
|
2019-11-04 01:18:55 +03:00
|
|
|
im.paste(255, (25, 10, 75, 90))
|
|
|
|
assert im.getbbox() == (10, 10, 90, 90)
|
|
|
|
|
|
|
|
im.paste(255, (-10, -10, 110, 110))
|
|
|
|
assert im.getbbox() == (0, 0, 100, 100)
|