예제 #1
0
파일: test_image.py 프로젝트: tjay/mapproxy
    def test_paletted_merge(self):
        if not hasattr(Image, 'FASTOCTREE'):
            raise SkipTest()

        # generate RGBA images with a transparent rectangle in the lower right
        img1 = ImageSource(Image.new('RGBA', (50, 50), (0, 255, 0, 255))).as_image()
        draw = ImageDraw.Draw(img1)
        draw.rectangle((25, 25, 49, 49), fill=(0, 0, 0, 0))
        paletted_img = quantize(img1, alpha=True)
        assert img_has_transparency(paletted_img)
        assert paletted_img.mode == 'P'

        rgba_img = Image.new('RGBA', (50, 50), (255, 0, 0, 255))
        draw = ImageDraw.Draw(rgba_img)
        draw.rectangle((25, 25, 49, 49), fill=(0, 0, 0, 0))

        img1 = ImageSource(paletted_img)
        img2 = ImageSource(rgba_img)

        # generate base image and merge the others above
        img3 = ImageSource(Image.new('RGBA', (50, 50), (0, 0, 255, 255)))
        result = merge_images([img3, img1, img2], ImageOptions(transparent=True))
        img = result.as_image()

        assert img.mode == 'RGBA'
        eq_(img.getpixel((49, 49)), (0, 0, 255, 255))
        eq_(img.getpixel((0, 0)), (255, 0, 0, 255))
예제 #2
0
    def test_rgb(self):
        if hasattr(Image, 'FASTOCTREE'):
            img = Image.new('RGB', (10, 10))             
            assert not img_has_transparency(img)

            img = quantize(img, alpha=False)
            assert not img_has_transparency(img)
예제 #3
0
    def test_rbga(self):
        img = Image.new("RGBA", (10, 10), (100, 200, 50, 255))
        img.paste((255, 50, 50, 0), (3, 3, 7, 7))
        assert img_has_transparency(img)

        img = quantize(img, alpha=True)
        assert img_has_transparency(img)
예제 #4
0
    def test_paletted_merge(self):
        if not hasattr(Image, 'FASTOCTREE'):
            raise SkipTest()

        # generate RGBA images with a transparent rectangle in the lower right
        img1 = ImageSource(Image.new('RGBA', (50, 50),
                                     (0, 255, 0, 255))).as_image()
        draw = ImageDraw.Draw(img1)
        draw.rectangle((25, 25, 49, 49), fill=(0, 0, 0, 0))
        paletted_img = quantize(img1, alpha=True)
        assert img_has_transparency(paletted_img)
        assert paletted_img.mode == 'P'

        rgba_img = Image.new('RGBA', (50, 50), (255, 0, 0, 255))
        draw = ImageDraw.Draw(rgba_img)
        draw.rectangle((25, 25, 49, 49), fill=(0, 0, 0, 0))

        img1 = ImageSource(paletted_img)
        img2 = ImageSource(rgba_img)

        # generate base image and merge the others above
        img3 = ImageSource(Image.new('RGBA', (50, 50), (0, 0, 255, 255)))
        result = merge_images([img3, img1, img2],
                              ImageOptions(transparent=True))
        img = result.as_image()

        assert img.mode == 'RGBA'
        eq_(img.getpixel((49, 49)), (0, 0, 255, 255))
        eq_(img.getpixel((0, 0)), (255, 0, 0, 255))
예제 #5
0
    def test_rgb(self):
        if hasattr(Image, 'FASTOCTREE'):
            img = Image.new('RGB', (10, 10))
            assert not img_has_transparency(img)

            img = quantize(img, alpha=False)
            assert not img_has_transparency(img)
예제 #6
0
    def test_rbga(self):
        if hasattr(Image, 'FASTOCTREE'):
            img = Image.new('RGBA', (10, 10), (100, 200, 50, 255))
            img.paste((255, 50, 50, 0), (3, 3, 7, 7))  
            assert img_has_transparency(img)

            img = quantize(img, alpha=True)
            assert img_has_transparency(img)
예제 #7
0
    def test_rbga(self):
        if hasattr(Image, 'FASTOCTREE'):
            img = Image.new('RGBA', (10, 10), (100, 200, 50, 255))
            img.paste((255, 50, 50, 0), (3, 3, 7, 7))
            assert img_has_transparency(img)

            img = quantize(img, alpha=True)
            assert img_has_transparency(img)
예제 #8
0
    def test_rgb(self):
        img = Image.new("RGB", (10, 10))
        assert not img_has_transparency(img)

        img = quantize(img, alpha=False)
        assert not img_has_transparency(img)