def test_negative_offset(self): sub_img = create_image((150, 150), color=[100, 120, 130, 140]) img = SubImageSource(sub_img, size=(100, 100), offset=(-50, 0), image_opts=ImageOptions()).as_image() eq_(img.getcolors(), [(100 * 100, (100, 120, 130, 140))])
def test_larger(self): sub_img = create_image((150, 150), color=[100, 120, 130, 140]) img = SubImageSource(sub_img, size=(100, 100), offset=(0, 0), image_opts=ImageOptions()).as_image() assert img.getcolors() == [(100 * 100, (100, 120, 130, 140))]
def test_outside(self): sub_img = create_image((50, 50), color=[100, 120, 130, 140]) img = SubImageSource( sub_img, size=(100, 100), offset=(200, 0), image_opts=ImageOptions(transparent=True)).as_image() eq_(img.getcolors(), [(100 * 100, (255, 255, 255, 0))])
def test_overlap_right(self): sub_img = create_image((50, 50), color=[100, 120, 130, 140]) img = SubImageSource( sub_img, size=(100, 100), offset=(75, 25), image_opts=ImageOptions(transparent=True)).as_image() eq_(sorted(img.getcolors()), [(25 * 50, (100, 120, 130, 140)), (100 * 100 - 25 * 50, (255, 255, 255, 0))])
def test_merge_overlapping_coverage(self): color1 = (255, 255, 0) color2 = (0, 255, 255) merger = LayerMerger() merger.add(ImageSource(Image.new('RGB', (10, 10), color1)), self.coverage1) merger.add(ImageSource(Image.new('RGB', (10, 10), color2)), self.coverage2) result = merger.merge(image_opts=ImageOptions(), bbox=(0, 0, 10, 10), bbox_srs=3857) img = result.as_image() eq_(img.mode, 'RGB') expected = create_image((10, 10), color1, 'RGB') draw = ImageDraw.Draw(expected) draw.polygon([(2, 2), (7, 2), (7, 7), (2, 7)], fill=color2) for x in range(0, 9): for y in range(0, 9): eq_(img.getpixel((x, y)), expected.getpixel((x, y)))
def test_outside(self): sub_img = create_image((50, 50), color=[100, 120, 130, 140]) img = SubImageSource(sub_img, size=(100, 100), offset=(200, 0), image_opts=ImageOptions(transparent=True)).as_image() eq_(img.getcolors(), [(100*100, (255, 255, 255, 0))])
def test_overlap_right(self): sub_img = create_image((50, 50), color=[100, 120, 130, 140]) img = SubImageSource(sub_img, size=(100, 100), offset=(75, 25), image_opts=ImageOptions(transparent=True)).as_image() eq_(sorted(img.getcolors()), [(25*50, (100, 120, 130, 140)), (100*100-25*50, (255, 255, 255, 0))])
def test_negative_offset(self): sub_img = create_image((150, 150), color=[100, 120, 130, 140]) img = SubImageSource(sub_img, size=(100, 100), offset=(-50, 0), image_opts=ImageOptions()).as_image() eq_(img.getcolors(), [(100*100, (100, 120, 130, 140))])