Пример #1
0
def test_Polygon3():
    img = Image(100, 200)

    points = ((10, 10), (20, 190), (90, 10), (50, 50))

    img.draw_polygon(points, fill_color='blue', line_color='red', line_width=4)
    img.save(outfile("test_image_poly3.bmp"))
Пример #2
0
def test_polygon_clip():
    img = Image(100, 200)

    points = ((-20, 10), (20, 250), (120, 10), (50, 50))

    img.draw_polygon(points, fill_color='blue', line_color='red')
    img.save(outfile("test_image_polygon_clip.bmp"))
Пример #3
0
def test_Polygon1():
    img = Image(100, 200)

    points = ((10, 10), (20, 190), (90, 10), (50, 50))

    img.draw_polygon(points, 'red')
    img.save(outfile("test_image_poly1.bmp"))
Пример #4
0
def test_draw_dots_large():
    img = Image(200, 200)

    img.draw_dots(((5, 5), ), diameter=3, color='red')

    img.draw_dots(((15, 15), ), diameter=4, color='red')

    img.draw_dots(((25, 25), ), diameter=5, color='red')

    img.draw_dots(((35, 35), ), diameter=6, color='red')

    img.draw_dots(((45, 45), ), diameter=7, color='red')

    img.draw_dots(((55, 55), ), diameter=9, color='red')

    img.draw_dots(((65, 65), ), diameter=12, color='red')

    img.draw_dots(((80, 80), ), diameter=15, color='red')

    img.draw_dots(((100, 100), ), diameter=20, color='red')

    img.draw_dots(((120, 120), ), diameter=30, color='red')

    img.draw_dots(((65, 65), ), diameter=12, color='red')

    img.save(outfile("test_image_dots_large.png"), "png")
Пример #5
0
def test_draw_x_large():
    img = Image(200, 200)

    img.draw_xes(((5, 5), ), diameter=3, color='red')

    img.draw_xes(((15, 15), ), diameter=4, color='red')

    img.draw_xes(((25, 25), ), diameter=5, color='purple')

    img.draw_xes(((35, 35), ), diameter=6, color='red')

    img.draw_xes(((45, 45), ), diameter=7, color='red')

    img.draw_xes(((55, 55), ), diameter=9, color='green')

    img.draw_xes(((65, 65), ), diameter=12, color='red', line_width=2)

    img.draw_xes(((80, 80), ), diameter=15, color='blue', line_width=3)

    img.draw_xes(((100, 100), ), diameter=20, color='fuchsia', line_width=4)

    img.draw_xes(((120, 120), ), diameter=30, color='red', line_width=5)

    img.draw_xes(((160, 160), ), diameter=40, color='red', line_width=10)

    img.save(outfile("test_image_x_large.png"), "png")
Пример #6
0
def test_Polygon2():
    img = Image(100, 200)

    points = ((10, 10), (20, 190), (90, 10), (50, 50))

    img.draw_polygon(points, fill_color='blue')

    img.save(outfile("test_image_poly2.bmp"))
Пример #7
0
def test_draw_dots3():
    img = Image(20, 20)

    img.draw_dots(((2, 2), (2, 18), (10, 10)), diameter=3)

    img.draw_dots(((18, 18), (18, 2)), diameter=4, color='red')

    img.save(outfile("test_image_points3.png"), "png")
Пример #8
0
def test_SetPixel():
    img = Image(5, 5)

    img.draw_pixel((0, 0), 'white')
    img.draw_pixel((1, 1), 'red')
    img.draw_pixel((2, 2), 'green')
    img.draw_pixel((3, 3), 'blue')

    img.save(outfile("test_image_pixel.bmp"))
    assert check_file("test_image_pixel.bmp")
Пример #9
0
def test_text():
    img = Image(200, 200)

    img.draw_text("Some Tiny Text", (20, 20), font="tiny", color='white')
    img.draw_text("Some Small Text", (20, 40), font="small", color='white')
    img.draw_text("Some Medium Text", (20, 60), font="medium", color='white')
    img.draw_text("Some Large Text", (20, 80), font="large", color='white')
    img.draw_text("Some Giant Text", (20, 100), font="giant", color='white')

    img.save(outfile("test_image_text.bmp"), "bmp")
Пример #10
0
def test_rectangles():
    img = Image(100, 200)

    img.draw_rectangle((10, 10), (30, 40), fill_color='blue')
    img.draw_rectangle((20, 50), (40, 70), line_color='blue', line_width=5)
    img.draw_rectangle((40, 80), (90, 220),
                       fill_color='white',
                       line_color='green',
                       line_width=2)

    img.save(outfile("test_image_rectangle.bmp"))
Пример #11
0
def test_clear_color():
    img = Image(100, 200)

    # just to put something in there to clear.
    img.draw_rectangle((-10, -10), (50, 100), fill_color='red')
    img.draw_rectangle((50, 100), (110, 210), fill_color='blue')

    img.save(outfile("test_image_clear_before2.png"), "png")
    img.clear(color='white')
    img.save(outfile("test_image_clear_after2.png"), "png")

    assert np.all(np.asarray(img).flat == img.get_color_index('white'))
Пример #12
0
def test_clip_draw():
    img = Image(100, 100)

    img.clip_rect = ((20, 20), (80, 80))

    img.draw_line((0, 0), (100, 100), color='red', line_width=4)
    img.draw_line((0, 100), (100, 0), color='blue', line_width=4)

    fname = "image_clip.bmp"
    img.save(outfile(fname))

    assert check_file(fname)
Пример #13
0
def test_copy_ul():
    """
    test copying parts of an image
    """
    img1 = Image(10, 10)
    img2 = Image(10, 10)

    img1.draw_rectangle((1, 1), (8, 8), fill_color='red')
    img2.draw_rectangle((0, 0), (9, 9), fill_color='blue')

    img2.copy(img1, (0, 0), (7, 7), (4, 4))

    img2.save(outfile("image_copy_upper_left.bmp"))
Пример #14
0
def test_line():
    img = Image(100, 200)

    img.draw_line((0, 0), (99, 199), 'white')
    img.draw_line((0, 199), (99, 0), 'red', line_width=2)
    img.draw_line((0, 100), (99, 100), 'green', line_width=4)
    img.draw_line((50, 0), (50, 199), 'blue', line_width=8)

    img.save(outfile("test_image_line.bmp"))
    assert check_file("test_image_line.bmp")

    with pytest.raises(TypeError):
        img.draw_line((0, 0), (99, 199), 'white', line_width='fred')
Пример #15
0
def test_text_align():
    img = Image(200, 200)

    img.draw_text("abcd", (0, 0), font="tiny", color='white')
    img.draw_text("abcd", (100, 0), font="small", color='white', align='ct')
    img.draw_text("abcd", (200, 0), font="medium", color='white', align='rt')
    img.draw_text("abcd", (200, 100), font="large", color='white', align='r')
    img.draw_text("abcd", (200, 200), font="tiny", color='white', align='rb')
    img.draw_text("abcd", (100, 200), font="small", color='white', align='cb')
    img.draw_text("abcd", (0, 200), font="medium", color='white', align='lb')
    img.draw_text("abcd", (0, 100), font="large", color='white', align='l')

    img.save(outfile("test_text_align.bmp"), "bmp")
Пример #16
0
def test_copy_transparent():
    """
    test copying parts of an image that are transparent
    """
    img1 = Image(10, 10)
    img2 = Image(10, 10)

    img1.draw_rectangle((0, 0), (9, 9), fill_color='red')
    img1.draw_rectangle((2, 2), (7, 7), fill_color='transparent')
    img2.draw_rectangle((0, 0), (9, 9), fill_color='blue')

    img2.copy(img1, (0, 0), (7, 7), (4, 4))

    img2.save(outfile("image_copy_trans.png"), file_type="png")
Пример #17
0
def test_copy2():
    """
    test copying parts of an image
    """
    img1 = Image(10, 10)
    img2 = Image(10, 10)

    img1.draw_rectangle((1, 1), (8, 8), fill_color='red')
    img2.draw_rectangle((0, 0), (9, 9), fill_color='blue')

    img2.copy(img1, (3, 3), (3, 3), (4, 4))

    img1.save(outfile("image_copy_middle1.bmp"))
    img2.save(outfile("image_copy_middle2.bmp"))
Пример #18
0
def test_save_image(filetype):
    img = Image(400, 300)

    img.draw_line((0, 0), (399, 299), 'white', line_width=4)
    img.draw_line((0, 299), (399, 0), 'green', line_width=4)

    fname = "test_image_save." + filetype
    img.save(outfile(fname), filetype)

    if filetype is not "jpg":  # jpeg is lossy and thus inconsistent
        assert check_file(fname)

    with pytest.raises(ValueError):
        img.save(outfile("test_image1.something"), "random_string")
Пример #19
0
def test_draw_x_lots():
    """
    test drawing a lot of dots
    """
    import random
    w, h, = 1000, 500
    img = Image(w, h)

    points = [(random.randint(0, w), random.randint(0, w))
              for _i in range(1000)]

    img.draw_xes(points, diameter=2, color='red')

    img.save(outfile("test_image_x_lots.png"), 'png')
Пример #20
0
def test_draw_dot():
    img = Image(
        100,
        100,
    )

    img.draw_dot((10, 10))
    img.draw_dot((20, 20), diameter=2, color='black')
    img.draw_dot((30, 30), diameter=3, color='red')
    img.draw_dot((40, 0), diameter=4, color='blue')
    img.draw_dot((50, 50), diameter=6, color='aqua')
    img.draw_dot((60, 60), diameter=8, color='lime')
    img.draw_dot((70, 70), diameter=10, color='fuchsia')
    img.draw_dot((80, 80), diameter=15, color='purple')

    img.save(outfile("test_image_dot.png"), "png")
Пример #21
0
def test_polyline():
    img = Image(100, 200)

    points = ((10, 10), (20, 190), (90, 10), (50, 50))

    img.draw_polyline(points, 'red', line_width=3)

    points = ((50, 50), (90, 190), (10, 10))

    img.draw_polyline(points, 'blue', line_width=5)

    with pytest.raises(ValueError):
        # can't accept just one point
        img.draw_polyline(((10, 10), ), 'blue')

    img.save(outfile("test_image_polyline.bmp"))
Пример #22
0
def test_copy1():
    """
    test copying a full image
    """
    img1 = Image(5, 5)
    img2 = Image(5, 5)

    img1.draw_pixel((0, 0), 'white')
    img1.draw_pixel((1, 1), 'red')
    img1.draw_pixel((2, 2), 'green')
    img1.draw_pixel((3, 3), 'blue')
    img1.draw_pixel((4, 4), 'gray')

    img2.copy(img1)

    img2.save(outfile("image_copy.bmp"))

    assert np.array_equal(np.array(img1), np.array(img2))
Пример #23
0
def test_add_colors():
    img = Image(10, 10, preset_colors='BW')

    assert img.get_color_names() == ['transparent', 'black', 'white']

    img.add_color('light grey', (220, 220, 220))

    assert img.get_color_names() == [
        'transparent', 'black', 'white', 'light grey'
    ]
    assert img.get_color_index('light grey') == 3

    img.draw_rectangle((2, 2), (7, 7), fill_color='light grey')
    img.save(outfile('test_image_grey.bmp'))

    with pytest.raises(ValueError):
        # color doesn't exist
        img.draw_rectangle((2, 2), (7, 7), fill_color='red')
Пример #24
0
def test_array_set():
    arr = np.array([[0, 1, 2], [3, 4, 5], [6, 7, 8], [9, 10, 11]],
                   dtype=np.uint8,
                   order='f')

    img = Image(arr.shape[0], arr.shape[1], preset_colors='web')

    img.set_data(arr)

    img.save(outfile('test_image_array1.bmp'))

    print img.get_color_names()

    for i in range(4):
        for j in range(3):
            print img.get_pixel_color((i, j)),
            print img.get_pixel_value((i, j))

    for y in range(img.height):
        for x in range(img.width):
            assert arr[x, y] == img.get_pixel_value((x, y))
Пример #25
0
def test_text_background():
    img = Image(200, 200)

    img.draw_text("abcd", (0, 0), font="tiny", color='white')
    img.draw_text("abcd", (100, 0), font="small", color='white', align='ct')
    img.draw_text("abcd", (200, 0),
                  font="medium",
                  color='white',
                  align='rt',
                  background='red')
    img.draw_text("abcd", (200, 100), font="large", color='white', align='r')
    img.draw_text("abcd", (200, 200), font="tiny", color='white', align='rb')
    img.draw_text("abcd", (100, 200),
                  font="small",
                  color='white',
                  align='cb',
                  background='green')
    img.draw_text("abcd", (0, 200), font="medium", color='white', align='lb')
    img.draw_text("abcd", (0, 100), font="large", color='white', align='l')
    img.draw_text("9999", (0, 0), font="tiny", color='white')
    img.draw_text("9999", (100, 0), font="small", color='red', align='ct')
    img.draw_text("9999", (200, 0),
                  font="medium",
                  color='white',
                  align='rt',
                  background='red')
    img.draw_text("9999", (200, 100), font="large", color='blue', align='r')
    img.draw_text("9999", (200, 200), font="tiny", color='white', align='rb')
    img.draw_text("9999", (100, 200),
                  font="small",
                  color='white',
                  align='cb',
                  background='green')
    img.draw_text("9999", (0, 200), font="medium", color='white', align='lb')
    img.draw_text("9999", (0, 100), font="large", color='white', align='l')

    img.save(outfile("test_text_background.bmp"), "bmp")
Пример #26
0
def test_cant_save_file():
    img = Image(width=400, height=400)

    with pytest.raises(IOError):
        img.save("a/non_existant/file_path")
Пример #27
0
def test_line_clip():
    img = Image(100, 200)

    img.draw_line((-30, -10), (150, 250), 'white')
    img.save(outfile("test_image_line_clip.bmp"))
Пример #28
0
def test_arc():
    img = Image(400, 600)

    # possible flags:  "Arc", "Pie", "Chord", "NoFill", "Edged"
    # (Arc and Pie are the same)
    center = (200, 150)

    # just the lines
    img.draw_arc(center,
                 380,
                 280,
                 start=-30,
                 end=30,
                 line_color='white',
                 style='arc',
                 draw_wedge=False)
    img.draw_arc(center,
                 380,
                 280,
                 start=30,
                 end=90,
                 line_color='white',
                 style='chord',
                 draw_wedge=False,
                 line_width=3)
    img.draw_arc(center,
                 380,
                 280,
                 start=90,
                 end=150,
                 line_color='white',
                 style='arc',
                 draw_wedge=True,
                 line_width=5)
    img.draw_arc(center,
                 380,
                 280,
                 start=150,
                 end=210,
                 line_color='white',
                 style='chord',
                 draw_wedge=True)

    # just fill
    img.draw_arc(center,
                 380,
                 280,
                 start=210,
                 end=270,
                 fill_color='purple',
                 style='arc')
    img.draw_arc(center,
                 380,
                 280,
                 start=270,
                 end=330,
                 fill_color='teal',
                 style='chord')

    # line and fill
    center = (200, 450)

    img.draw_arc(center,
                 380,
                 280,
                 start=30,
                 end=90,
                 line_color='white',
                 fill_color='green',
                 style='chord')
    # img.draw_arc(center, 380, 280, start= 90, end= 150, line_color='white',
    #              fill_color='blue', styles=['NoFill'])
    img.draw_arc(center,
                 380,
                 280,
                 start=150,
                 end=210,
                 line_color='green',
                 fill_color='white',
                 style='arc')
    # img.draw_arc(center, 380, 280, start=210, end= 270, line_color='white',
    #              fill_color='purple', styles=['Chord','Edged', 'NoFill'])
    img.draw_arc(center,
                 380,
                 280,
                 start=270,
                 end=330,
                 line_color='blue',
                 fill_color='red',
                 line_width=3)

    img.save(outfile("test_image_arc.bmp"))

    # errors
    with pytest.raises(ValueError):
        img.draw_arc(center,
                     380,
                     280,
                     start=30,
                     end=90,
                     line_color='white',
                     style='fred')