示例#1
0
def test_same_color_outline():
    # Prepare shape
    x0, y0 = 5, 5
    x1, y1 = 5, 50
    x2, y2 = 95, 50
    x3, y3 = 95, 5

    s = ImageDraw.Outline()
    s.move(x0, y0)
    s.curve(x1, y1, x2, y2, x3, y3)
    s.line(x0, y0)

    # Begin
    for mode in ["RGB", "L"]:
        for fill, outline in [["red", None], ["red", "red"], ["red", "#f00"]]:
            for operation, args in {
                    "chord": [BBOX1, 0, 180],
                    "ellipse": [BBOX1],
                    "shape": [s],
                    "pieslice": [BBOX1, -90, 45],
                    "polygon": [[(18, 30), (85, 30), (60, 72)]],
                    "rectangle": [BBOX1],
            }.items():
                # Arrange
                im = Image.new(mode, (W, H))
                draw = ImageDraw.Draw(im)

                # Act
                draw_method = getattr(draw, operation)
                args += [fill, outline]
                draw_method(*args)

                # Assert
                expected = f"Tests/images/imagedraw_outline_{operation}_{mode}.png"
                assert_image_similar_tofile(im, expected, 1)
示例#2
0
def test_transform():
    # Arrange
    im = Image.new("RGB", (100, 100), "white")
    expected = im.copy()
    draw = ImageDraw.Draw(im)

    # Act
    s = ImageDraw.Outline()
    s.line(0, 0)
    s.transform((0, 0, 0, 0, 0, 0))

    draw.shape(s, fill=1)

    # Assert
    assert_image_equal(im, expected)
示例#3
0
def test_shape2():
    # Arrange
    im = Image.new("RGB", (100, 100), "white")
    draw = ImageDraw.Draw(im)
    x0, y0 = 95, 95
    x1, y1 = 95, 50
    x2, y2 = 5, 50
    x3, y3 = 5, 95

    # Act
    s = ImageDraw.Outline()
    s.move(x0, y0)
    s.curve(x1, y1, x2, y2, x3, y3)
    s.line(x0, y0)

    draw.shape(s, outline="blue")

    # Assert
    assert_image_equal(im, Image.open("Tests/images/imagedraw_shape2.png"))
示例#4
0
def test_shape1():
    # Arrange
    im = Image.new("RGB", (100, 100), "white")
    draw = ImageDraw.Draw(im)
    x0, y0 = 5, 5
    x1, y1 = 5, 50
    x2, y2 = 95, 50
    x3, y3 = 95, 5

    # Act
    s = ImageDraw.Outline()
    s.move(x0, y0)
    s.curve(x1, y1, x2, y2, x3, y3)
    s.line(x0, y0)

    draw.shape(s, fill=1)

    # Assert
    assert_image_equal_tofile(im, "Tests/images/imagedraw_shape1.png")
示例#5
0
    def test_same_color_outline(self):
        # Prepare shape
        x0, y0 = 5, 5
        x1, y1 = 5, 50
        x2, y2 = 95, 50
        x3, y3 = 95, 5

        s = ImageDraw.Outline()
        s.move(x0, y0)
        s.curve(x1, y1, x2, y2, x3, y3)
        s.line(x0, y0)

        # Begin
        for mode in ["RGB", "L"]:
            for fill, outline in [
                ["red", None],
                ["red", "red"],
                ["red", "#f00"]
            ]:
                for operation, args in {
                    'chord':[BBOX1, 0, 180],
                    'ellipse':[BBOX1],
                    'shape':[s],
                    'pieslice':[BBOX1, -90, 45],
                    'polygon':[[(18, 30), (85, 30), (60, 72)]],
                    'rectangle':[BBOX1]
                }.items():
                    # Arrange
                    im = Image.new(mode, (W, H))
                    draw = ImageDraw.Draw(im)

                    # Act
                    draw_method = getattr(draw, operation)
                    args += [fill, outline]
                    draw_method(*args)

                    # Assert
                    expected = ("Tests/images/imagedraw_outline"
                                "_{}_{}.png".format(operation, mode))
                    self.assert_image_similar(im, Image.open(expected), 1)