2014-09-05 14:03:56 +04:00
|
|
|
from helper import unittest, PillowTestCase, hopper
|
2012-10-16 00:26:38 +04:00
|
|
|
|
|
|
|
from PIL import Image
|
|
|
|
|
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
class TestImageGetBbox(PillowTestCase):
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
def test_sanity(self):
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2014-09-05 14:03:56 +04:00
|
|
|
bbox = hopper().getbbox()
|
2014-06-10 13:10:47 +04:00
|
|
|
self.assertIsInstance(bbox, tuple)
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
def test_bbox(self):
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
# 8-bit mode
|
|
|
|
im = Image.new("L", (100, 100), 0)
|
|
|
|
self.assertEqual(im.getbbox(), None)
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
im.paste(255, (10, 25, 90, 75))
|
|
|
|
self.assertEqual(im.getbbox(), (10, 25, 90, 75))
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
im.paste(255, (25, 10, 75, 90))
|
|
|
|
self.assertEqual(im.getbbox(), (10, 10, 90, 90))
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
im.paste(255, (-10, -10, 110, 110))
|
|
|
|
self.assertEqual(im.getbbox(), (0, 0, 100, 100))
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
# 32-bit mode
|
|
|
|
im = Image.new("RGB", (100, 100), 0)
|
|
|
|
self.assertEqual(im.getbbox(), None)
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
im.paste(255, (10, 25, 90, 75))
|
|
|
|
self.assertEqual(im.getbbox(), (10, 25, 90, 75))
|
|
|
|
|
|
|
|
im.paste(255, (25, 10, 75, 90))
|
|
|
|
self.assertEqual(im.getbbox(), (10, 10, 90, 90))
|
|
|
|
|
|
|
|
im.paste(255, (-10, -10, 110, 110))
|
|
|
|
self.assertEqual(im.getbbox(), (0, 0, 100, 100))
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|