Exemplo n.º 1
0
def name_select():
    """
    Como a função sugere essa função desenha o nome da pessoa.
    Tem um macete para dropshadow, que também é usado na função de localizaçõo
    não tem mais o que explicar, não sei se é possível fazer em apenas um
    Drawing(), provavelmente é mas o programa funciona do jeito que tá
    """
    dimensions = {'width': 420,
                  'height': 150}
    with nested(Image(filename='nova{}.png'.format(boneca.lower())),
                Image(background=Color('transparent'), **dimensions)) as (img, shadow):
        with Drawing() as ctx:
            ctx.font = 'verdanab.ttf'
            ctx.fill_color = "black"
            ctx.text_alignment = 'center'
            ctx.font_size = 27.57
            ctx.text(210, 31, '{}'.format(name))
            ctx(shadow)
        shadow.gaussian_blur(8, 8)
        with Drawing() as draw:
            draw.font = 'verdanab.ttf'
            draw.fill_color = "rgb(255, 255, 255)"
            draw.font_size = 27.57
            draw.text_alignment = 'center'
            draw.stroke_opacity = 78
            draw.text(210, 33, '{}'.format(name))
            draw(shadow)
        img.composite(shadow, 0, 0)
        img.save(filename='ficha {}.png'.format(name))
Exemplo n.º 2
0
def MakeFrontCover(pCode, pName, pChapter, pTitle1, pTitle2):
  with Image(filename='empty_youtube_cover.png') as converted:
        converted.format = 'jpg'
        dimensions['width']=converted.width
        dimensions['height']=converted.height
        with nested(converted.clone(),
            Image(background=Color('transparent'), **dimensions)) as (bg, shadow):
            # Draw the drop shadow
            with Drawing() as ctx:
                ctx.fill_color = Color('rgba(3, 3, 3, 0.6)')
                ctx.font = '/usr/share/fonts/truetype/wqy/wqy-zenhei.ttc'
                ctx.font_size = 100
                ctx.text(240, 160, pName)
                ctx.text(280, 320, pChapter)
                ctx.text(280, 480, pTitle1)
                ctx.text(280, 640, pTitle2)
                ctx(shadow)
                # Apply filter
                shadow.gaussian_blur(4, 2)
                # Draw text
                with Drawing() as ctx:
                    ctx.fill_color = Color('rgb(76, 175, 80)')
                    ctx.font = '/usr/share/fonts/truetype/wqy/wqy-zenhei.ttc'
                    ctx.font_size = 100
                    ctx.text(240-4, 160-4, pName)
                    ctx.text(280-4, 320-4, pChapter)
                    ctx.text(280-4, 480-4, pTitle1)
                    ctx.text(280-4, 640-4, pTitle2)
                    ctx(shadow)
                bg.composite(shadow, 0, 0)
                bg.save(filename='cover/'+pCode+'.jpg')
  return
Exemplo n.º 3
0
def test_draw_comment():
    comment = 'pikachu\'s ghost'
    expected = '#pikachu\'s ghost\n'
    with nested(Image(width=1, height=1), Drawing()) as (img, draw):
        draw.comment(comment)
        draw(img)
        blob = img.make_blob(format="mvg")
        assert expected == text(blob)
Exemplo n.º 4
0
def test_draw_point():
    with nested(Color('#fff'), Color('#000')) as (white, black):
        with Image(width=5, height=5, background=white) as img:
            with Drawing() as draw:
                draw.stroke_color = black
                draw.point(2,2)
                draw.draw(img)
                assert img[2,2] == black
Exemplo n.º 5
0
def test_draw_color():
    with nested(Color('#fff'), Color('#000')) as (white, black):
        with Image(width=50, height=50, background=white) as img:
            with Drawing() as draw:
                draw.fill_color = black
                draw.color(25, 25, 'floodfill')
                draw.draw(img)
                assert img[25, 25] == black
Exemplo n.º 6
0
def test_draw_matte():
    with nested(Color('#fff'), Color('transparent')) as (white, transparent):
        with Image(width=50, height=50, background=white) as img:
            with Drawing() as draw:
                draw.fill_opacity = 0
                draw.matte(25, 25, 'floodfill')
                draw.draw(img)
                assert img[25, 25] == transparent
Exemplo n.º 7
0
def test_draw_point():
    with nested(Color('#fff'), Color('#000')) as (white, black):
        with Image(width=5, height=5, background=white) as img:
            with Drawing() as draw:
                draw.stroke_color = black
                draw.point(2, 2)
                draw.draw(img)
                assert img[2, 2] == black
Exemplo n.º 8
0
def test_draw_comment():
    comment = 'pikachu\'s ghost'
    expected = '#pikachu\'s ghost\n'
    with nested(Image(width=1, height=1), Drawing()) as (img, draw):
        draw.comment(comment)
        draw(img)
        blob = img.make_blob(format="mvg")
        assert expected == text(blob)
Exemplo n.º 9
0
def test_draw_translate():
    with nested(Color('#fff'), Color('#000')) as (white, black):
        with Image(width=50, height=50, background=white) as img:
            with Drawing() as draw:
                draw.stroke_color = black
                draw.translate(x=5, y=5)
                draw.line((3, 3), (35, 35))
                draw.draw(img)
                assert img[40, 40] == black
Exemplo n.º 10
0
def test_draw_matte():
    with nested(Color('#fff'),
                Color('transparent')) as (white, transparent):
        with Image(width=50, height=50, background=white) as img:
            with Drawing() as draw:
                draw.fill_opacity = 0
                draw.matte(25,25,'floodfill')
                draw.draw(img)
                assert img[25,25] == transparent
Exemplo n.º 11
0
def test_draw_skew():
    with nested(Color('#fff'), Color('#000')) as (white, black):
        with Image(width=50, height=50, background=white) as img:
            with Drawing() as draw:
                draw.stroke_color = black
                draw.skew(x=11, y=-24)
                draw.line((3, 3), (35, 35))
                draw.draw(img)
                assert img[43, 42] == black
Exemplo n.º 12
0
def test_draw_color():
    with nested(Color('#fff'),
                Color('#000')) as (white, black):
        with Image(width=50, height=50, background=white) as img:
            with Drawing() as draw:
                draw.fill_color = black
                draw.color(25,25,'floodfill')
                draw.draw(img)
                assert img[25,25] == black
Exemplo n.º 13
0
def test_draw_skew():
    with nested(Color('#fff'),
                Color('#000')) as (white, black):
        with Image(width=50, height=50, background=white) as img:
            with Drawing() as draw:
                draw.stroke_color = black
                draw.skew(x=11,y=-24)
                draw.line((3, 3), (35, 35))
                draw.draw(img)
                assert img[43,42] == black
Exemplo n.º 14
0
def test_draw_affine(display, fx_wand):
    with nested(Color('skyblue'), Color('black')) as (skyblue, black):
        with Image(width=100, height=100, background=skyblue) as img:
            img.format = 'png'
            fx_wand.affine([1.5, 0.5, 0, 1.5, 45, 25])
            fx_wand.rectangle(top=5, left=5, width=25, height=25)
            fx_wand.draw(img)
            display(img)
            assert img[25, 25] == skyblue
            assert img[75, 75] == black
Exemplo n.º 15
0
def test_draw_translate():
    with nested(Color('#fff'),
                Color('#000')) as (white, black):
        with Image(width=50, height=50, background=white) as img:
            with Drawing() as draw:
                draw.stroke_color = black
                draw.translate(x=5, y=5)
                draw.line((3, 3), (35, 35))
                draw.draw(img)
                assert img[40,40] == black
Exemplo n.º 16
0
def test_draw_circle(fx_asset):
    with nested(Color('#fff'),
                Color('#000')) as (white, black):
        with Image(width=50, height=50, background=white) as img:
            with Drawing() as draw:
                draw.fill_color = black
                draw.circle((25, 25), # Origin
                            (40, 40)) # Perimeter
                draw.draw(img)
                assert img[5,5] == img[45,45] == white
                assert img[25,25] == black
Exemplo n.º 17
0
    def test_setting_base_on_ptl_is_same_as_drawing_text(self):
        width = 100
        text = "Hpqrs"
        left = 0
        base = 20
        median = 40
        median_offset_for_font_size_12 = 6
        bg_color = "White"
        bg = ColorBackgroundLayer("bg", content=bg_color)
        l = PointTextLayer("l",
                           "Arial",
                           12,
                           "Black",
                           content=text,
                           left=NA(left),
                           base=NA(base))
        l2 = PointTextLayer("l2",
                            "Arial",
                            12,
                            "Black",
                            content=text,
                            left=NA(left),
                            median=NA(median))

        temp = Template("temp",
                        l,
                        l2,
                        bg,
                        left=NA(0),
                        right=NA(width),
                        top=NA(0),
                        bottom=NA(width))
        temp.update_bounds()
        img = temp.render()
        img.save(
            filename=
            "tests/images/test_setting_base_on_ptl_is_same_as_drawing_text.png"
        )

        with nested(
                Image(width=width, height=width, background=Color(bg_color)),
                Drawing()) as (img2, draw):
            draw.font = l.font
            draw.font_size = l.size
            draw.text(left, base, text)
            draw.text(left, median + median_offset_for_font_size_12, text)
            draw(img2)
            img2.save(
                filename=
                "tests/images/test_setting_base_on_ptl_is_same_as_drawing_text_2.png"
            )

            location, diff = img.similarity(img2, metric="absolute")
            assert diff == 0
Exemplo n.º 18
0
def test_draw_polyline(fx_wand):
    with nested(Color('#fff'), Color('#f00'),
                Color('#00f')) as (white, red, blue):
        with Image(width=50, height=50, background=white) as img:
            with Drawing() as draw:
                draw.fill_color = blue
                draw.stroke_color = red
                draw.polyline([(10, 10), (40, 25), (10, 40)])
                draw.draw(img)
                assert img[10, 25] == img[25, 25] == blue
                assert img[35, 15] == img[35, 35] == white
Exemplo n.º 19
0
def test_draw_circle(fx_asset):
    with nested(Color('#fff'), Color('#000')) as (white, black):
        with Image(width=50, height=50, background=white) as img:
            with Drawing() as draw:
                draw.fill_color = black
                draw.circle(
                    (25, 25),  # Origin
                    (40, 40))  # Perimeter
                draw.draw(img)
                assert img[5, 5] == img[45, 45] == white
                assert img[25, 25] == black
Exemplo n.º 20
0
def test_draw_affine(display, fx_wand):
    with nested(Color('skyblue'),
                Color('black')) as (skyblue, black):
        with Image(width=100, height=100, background=skyblue) as img:
            img.format = 'png'
            fx_wand.affine([1.5, 0.5, 0, 1.5, 45, 25])
            fx_wand.rectangle(top=5,left=5, width=25, height=25)
            fx_wand.draw(img)
            display(img)
            assert img[25, 25] == skyblue
            assert img[75, 75] == black
Exemplo n.º 21
0
def test_composite(fx_wand):
    with nested(Color('#fff'), Color('#000')) as (white, black):
        with Image(width=50, height=50, background=white) as img:
            fx_wand.fill_color = black
            fx_wand.stroke_color = black
            fx_wand.rectangle(25, 25, 49, 49)
            fx_wand.draw(img)
            fx_wand.composite("replace", 0, 0, 25, 25, img)
            fx_wand.draw(img)
            assert img[45, 45] == img[20, 20] == black
            assert img[45, 20] == img[20, 45] == white
Exemplo n.º 22
0
def test_draw_bezier(fx_wand):
    with nested(Color('#fff'), Color('#f00'),
                Color('#00f')) as (white, red, blue):
        with Image(width=50, height=50, background=white) as img:
            with Drawing() as draw:
                draw.fill_color = blue
                draw.stroke_color = red
                draw.bezier([(10, 10), (10, 40), (40, 10), (40, 40)])
                draw.draw(img)
                assert img[10, 10] == img[25, 25] == img[40, 40] == red
                assert img[34, 32] == img[15, 18] == blue
                assert img[34, 38] == img[15, 12] == white
Exemplo n.º 23
0
    def get_in_depth_font_metrics(self):
        # if self.content is None:
        #     return {
        #         "median" : 0,
        #         "descender" : 0,
        #         "cap" : 0,
        #         "ascender": 0,
        #         "absolute_ascender": 0
        #         "absolute_descender": 0
        #     }
        # else:
        with nested(Image(width=1, height=1), Drawing()) as (temp_image, draw):
            draw.font = self.font
            draw.font_size = self.size

            max_descender = 0
            max_ascender = 0
            alpha_metrics = {}
            for l in al + au:
                alpha_metrics[l] = draw.get_font_metrics(temp_image, l, False)
                if alpha_metrics[l].y2 > max_ascender:
                    max_ascender = alpha_metrics[l].y2
                if alpha_metrics[l].y1 < max_descender:
                    max_descender = alpha_metrics[l].y1

            a_asc = 0
            a_desc = 0
            if self.content is None or self.content == "":
                a_asc = max_ascender
                a_asc = max_descender
            else:
                for l in self.content:
                    if l not in alpha_metrics:
                        alpha_metrics[l] = draw.get_font_metrics(temp_image, l, False)
                    if alpha_metrics[l].y2 > a_asc:
                        a_asc = alpha_metrics[l].y2
                    if alpha_metrics[l].y1 < a_desc:
                        a_desc = alpha_metrics[l].y1

            ml = draw.get_font_metrics(temp_image, al)
            mu = draw.get_font_metrics(temp_image, au)

            max_ascender = ceil(abs(max_ascender - max(ml.y2, mu.y2)))
            # absolute_height = ceil(a_asc) + ceil(- a_desc)

        return { # TODO maybe make cap relative to base
            "median" : ceil(ml.y2),
            "cap" : ceil(mu.y2),
            "ascender": ceil(max_ascender),
            "descender" : ceil(- max_descender),
            "absolute_ascender": ceil(a_asc),
            "absolute_descender": ceil(- a_desc),
        }
Exemplo n.º 24
0
def test_draw_scale(display, fx_wand):
    with nested(Color("#fff"), Color("#000")) as (white, black):
        with Image(width=50, height=50, background=white) as img:
            fx_wand.fill_color = black
            fx_wand.scale(x=2.0, y=0.5)
            fx_wand.rectangle(top=5, left=5, width=20, height=20)
            fx_wand.draw(img)
            display(img)
            # if width was scaled up by 200%
            assert img[45, 10] == black
            # if height was scaled down by 50%
            assert img[20, 20] == white
Exemplo n.º 25
0
def test_draw_polyline(fx_wand):
    with nested(Color('#fff'),
                Color('#f00'),
                Color('#00f')) as (white, red, blue):
        with Image(width=50, height=50, background=white) as img:
            with Drawing() as draw:
                draw.fill_color = blue
                draw.stroke_color = red
                draw.polyline([(10, 10), (40, 25), (10, 40)])
                draw.draw(img)
                assert img[10, 25] == img[25, 25] == blue
                assert img[35, 15] == img[35, 35] == white
Exemplo n.º 26
0
def test_composite(fx_wand):
    with nested(Color('#fff'),
                Color('#000')) as (white, black):
        with Image(width=50, height=50, background=white) as img:
            fx_wand.fill_color = black
            fx_wand.stroke_color = black
            fx_wand.rectangle(25, 25, 49, 49)
            fx_wand.draw(img)
            fx_wand.composite("replace", 0, 0, 25, 25, img)
            fx_wand.draw(img)
            assert img[45,45] == img[20,20] == black
            assert img[45,20] == img[20,45] == white
Exemplo n.º 27
0
def test_draw_scale(display, fx_wand):
    with nested(Color("#fff"),
                Color("#000")) as (white, black):
        with Image(width=50, height=50, background=white) as img:
            fx_wand.fill_color = black
            fx_wand.scale(x=2.0, y=0.5)
            fx_wand.rectangle(top=5, left=5, width=20, height=20)
            fx_wand.draw(img)
            display(img)
            # if width was scaled up by 200%
            assert img[45,10] == black
            # if height was scaled down by 50%
            assert img[20,20] == white
Exemplo n.º 28
0
def test_set_fill_pattern_url(display, fx_wand):
    with nested(Color("#fff"), Color("#0f0"),
                Color("#000")) as (white, green, black):
        with Image(width=50, height=50, background=white) as img:
            fx_wand.push_pattern('green_circle', 0, 0, 10, 10)
            fx_wand.fill_color = green
            fx_wand.stroke_color = black
            fx_wand.circle(origin=(5, 5), perimeter=(5, 0))
            fx_wand.pop_pattern()
            fx_wand.set_fill_pattern_url('#green_circle')
            fx_wand.rectangle(top=5, left=5, width=40, height=40)
            fx_wand.draw(img)
            display(img)
            assert img[25, 25] == green
Exemplo n.º 29
0
def test_draw_rectangle(kwargs, display, fx_wand):
    with nested(Color('#fff'), Color('#333'),
                Color('#ccc')) as (white, black, gray):
        with Image(width=50, height=50, background=white) as img:
            fx_wand.stroke_width = 2
            fx_wand.fill_color = black
            fx_wand.stroke_color = gray
            fx_wand.rectangle(left=10, top=10, **dict(kwargs))
            fx_wand.draw(img)
            display(img)
            assert (img[7, 7] == img[7, 42] == img[42, 7] == img[42, 42] ==
                    img[0, 0] == img[49, 49] == white)
            assert (img[12, 12] == img[12, 38] == img[38, 12] == img[38, 38] ==
                    black)
Exemplo n.º 30
0
def test_draw_rectangle_with_radius(kwargs, display, fx_wand):
    with nested(Color('#fff'),
                Color('#333'),
                Color('#ccc')) as (white, black, gray):
        with Image(width=50, height=50, background=white) as img:
            fx_wand.stroke_width = 2
            fx_wand.fill_color = black
            fx_wand.stroke_color = gray
            fx_wand.rectangle(left=10, top=10,
                              width=30, height=30, **dict(kwargs))
            fx_wand.draw(img)
            display(img)
            assert img[10, 10] == img[40, 40] == white
            assert img[26, 12] == img[26, 36] == black
Exemplo n.º 31
0
def textShadowWand(image=None,
                   filePath=None,
                   fontSize=None,
                   place=None,
                   inputText=None,
                   blur=(10, 5),
                   fillcolor=None,
                   shadowcolor=(0, 0, 0, 0.5),
                   traceback=None):
    dimensions = {'width': image[0], 'height': image[1]}
    print(dimensions)
    with nested(Image(filename=(filePath), **dimensions),
                Image(background=Color('transparent'),
                      **dimensions)) as (bg, shadow):
        # Draw the drop shadow
        with Drawing() as ctx:
            ctx.font = 'Candice'
            ctx.push()
            thecolor = str('rgba' + str(shadowcolor))
            print('thecolor : ', thecolor)
            # str('rgba'+(3, 3, 3, 1))
            ctx.fill_color = Color(thecolor)
            # ctx.fill_color = Color('rgba(0,0,0,0.33)')
            ctx.font_size = fontSize
            ctx.text(place[0], place[1], inputText)
            print(place[0], place[1], inputText)
            print('ctx is ', ctx)
            ctx(shadow)
        # Apply filter
        # print(np.array(shadow.shape))

        shadow.gaussian_blur(7, 4)
        # Draw text
        with Drawing() as ctx:
            thecolor = str('rgba' + str(fillcolor))
            print('thecolor : ', thecolor)
            ctx.fill_color = Color(thecolor)
            ctx.font_size = fontSize
            ctx.text(place[0], place[1], inputText)
            print(place[0], place[1], 'LinkGish')
            ctx(shadow)
        bg.composite(shadow, 0, 0)
        traceback = str(traceback)
        bg.save(
            filename=
            '/home/linkgish/Desktop/WebApp2/GeneticDesignProject/OutputWand.png'
        )
        #wand.display.display(bg)

    return bg
Exemplo n.º 32
0
def test_draw_rectangle_with_radius(kwargs, display, fx_wand):
    with nested(Color('#fff'),
                Color('#333'),
                Color('#ccc')) as (white, black, gray):
        with Image(width=50, height=50, background=white) as img:
            fx_wand.stroke_width = 2
            fx_wand.fill_color = black
            fx_wand.stroke_color = gray
            fx_wand.rectangle(left=10, top=10,
                              width=30, height=30, **dict(kwargs))
            fx_wand.draw(img)
            display(img)
            assert img[10, 10] == img[40, 40] == white
            assert img[26, 12] == img[26, 36] == black
Exemplo n.º 33
0
def test_draw_arc(fx_asset):
    with nested(Color('#fff'),
                Color('#f00'),
                Color('#000')) as (white, red, black):
        with Image(width=50, height=50, background=white) as img:
            with Drawing() as draw:
                draw.fill_color = red
                draw.stroke_color = black
                draw.arc((10, 10), # Start
                         (40, 40), # End
                         (-90, 90)) # Degree
                draw.draw(img)
                assert img[20,25] == white
                assert img[30,25] == red
                assert img[40,25] == black
Exemplo n.º 34
0
def test_draw_arc(fx_asset):
    with nested(Color('#fff'), Color('#f00'),
                Color('#000')) as (white, red, black):
        with Image(width=50, height=50, background=white) as img:
            with Drawing() as draw:
                draw.fill_color = red
                draw.stroke_color = black
                draw.arc(
                    (10, 10),  # Start
                    (40, 40),  # End
                    (-90, 90))  # Degree
                draw.draw(img)
                assert img[20, 25] == white
                assert img[30, 25] == red
                assert img[40, 25] == black
Exemplo n.º 35
0
def test_path_curve_to_quadratic_bezier():
    with nested(Color('#fff'),
                Color('#f00'),
                Color('#00f')) as (white, red, blue):
        with Image(width=50, height=50, background=white) as img:
            with Drawing() as draw:
                draw.fill_color = blue
                draw.stroke_color = red
                draw = (draw.path_start()
                        .path_move(to=(0, 25), relative=True)
                        .path_curve_to_quadratic_bezier(to=(50, 25), control=(25, 50))
                        .path_curve_to_quadratic_bezier(to=(-20, -20), control=(-25, 0), relative=True)
                        .path_finish())
                draw.draw(img)
                assert img[30,5] == red
Exemplo n.º 36
0
def test_set_fill_pattern_url(display, fx_wand):
    with nested(Color("#fff"),
                Color("#0f0"),
                Color("#000")) as (white, green, black):
        with Image(width=50, height=50, background=white) as img:
            fx_wand.push_pattern('green_circle',0 , 0, 10, 10)
            fx_wand.fill_color = green
            fx_wand.stroke_color = black
            fx_wand.circle(origin=(5, 5), perimeter=(5, 0))
            fx_wand.pop_pattern()
            fx_wand.set_fill_pattern_url('#green_circle')
            fx_wand.rectangle(top=5, left=5, width=40, height=40)
            fx_wand.draw(img)
            display(img)
            assert img[25,25] == green
Exemplo n.º 37
0
def test_path_curve_to_quadratic_bezier():
    with nested(Color('#fff'), Color('#f00'),
                Color('#00f')) as (white, red, blue):
        with Image(width=50, height=50, background=white) as img:
            with Drawing() as draw:
                draw.fill_color = blue
                draw.stroke_color = red
                draw = (draw.path_start().path_move(
                    to=(0, 25), relative=True).path_curve_to_quadratic_bezier(
                        to=(50, 25),
                        control=(25, 50)).path_curve_to_quadratic_bezier(
                            to=(-20, -20), control=(-25, 0),
                            relative=True).path_finish())
                draw.draw(img)
                assert img[30, 5] == red
Exemplo n.º 38
0
def test_draw_rectangle(kwargs, display, fx_wand):
    with nested(Color('#fff'),
                Color('#333'),
                Color('#ccc')) as (white, black, gray):
        with Image(width=50, height=50, background=white) as img:
            fx_wand.stroke_width = 2
            fx_wand.fill_color = black
            fx_wand.stroke_color = gray
            fx_wand.rectangle(left=10, top=10, **dict(kwargs))
            fx_wand.draw(img)
            display(img)
            assert (img[7, 7] == img[7, 42] == img[42, 7] ==
                    img[42, 42] == img[0, 0] == img[49, 49] == white)
            assert (img[12, 12] == img[12, 38] == img[38, 12] ==
                    img[38, 38] == black)
Exemplo n.º 39
0
def test_draw_bezier(fx_wand):
    with nested(Color('#fff'),
                Color('#f00'),
                Color('#00f')) as (white, red, blue):
        with Image(width=50, height=50, background=white) as img:
            with Drawing() as draw:
                draw.fill_color = blue
                draw.stroke_color = red
                draw.bezier([(10,10),
                             (10,40),
                             (40,10),
                             (40,40)])
                draw.draw(img)
                assert img[10,10] == img[25,25] == img[40,40] == red
                assert img[34,32] == img[15,18] == blue
                assert img[34,38] == img[15,12] == white
Exemplo n.º 40
0
def test_draw_path_line():
    with nested(Color('#fff'), Color('#f00'),
                Color('#00f')) as (white, red, blue):
        with Image(width=50, height=50, background=white) as img:
            with Drawing() as draw:
                draw.fill_color = blue
                draw.stroke_color = red
                draw = (draw.path_start().path_move(to=(5, 5)).path_move(
                    to=(5, 5), relative=True).path_line(to=(40, 40)).path_line(
                        to=(0, -10), relative=True).path_horizontal_line(
                            x=45).path_vertical_line(
                                y=25).path_horizontal_line(
                                    x=-5, relative=True).path_vertical_line(
                                        y=-5, relative=True).path_finish())
                draw.draw(img)
                assert img[40, 40] == img[40, 30] == red
                assert img[45, 25] == img[40, 20] == red
Exemplo n.º 41
0
def test_path_curve():
    with nested(Color('#fff'),
                Color('#f00'),
                Color('#00f')) as (white, red, blue):
        with Image(width=50, height=50, background=white) as img:
            with Drawing() as draw:
                draw.fill_color = blue
                draw.stroke_color = red
                draw = (draw.path_start()
                        .path_move(to=(0,25), relative=True)
                        .path_curve(to=(25,25), controls=((0, 0), (25, 0)))
                        .path_curve(to=(25,0), controls=((0, 25), (25, 25)), relative=True)
                        .path_finish())
                draw.draw(img)
                assert img[25,25] == red
                assert img[35,35] == img[35,35] == blue
                assert img[35,15] == img[15,35] == white
Exemplo n.º 42
0
def test_draw_path_elliptic_arc():
    with nested(Color('#fff'),
                Color('#f00'),
                Color('#00f')) as (white, red, blue):
        with Image(width=50, height=50, background=white) as img:
            with Drawing() as draw:
                draw.fill_color = blue
                draw.stroke_color = red
                draw = (draw.path_start()
                        .path_move(to=(25,0))
                        .path_elliptic_arc(to=(25, 50), radius=(15, 25))
                        .path_elliptic_arc(to=(0,-15), radius=(5, 5), clockwise=False, relative=True)
                        .path_close()
                        .path_finish())
                draw.draw(img)
                assert img[25,35] == img[25,20] == red
                assert img[15,25] == img[30,45] == blue
Exemplo n.º 43
0
def test_draw_path_elliptic_arc():
    with nested(Color('#fff'), Color('#f00'),
                Color('#00f')) as (white, red, blue):
        with Image(width=50, height=50, background=white) as img:
            with Drawing() as draw:
                draw.fill_color = blue
                draw.stroke_color = red
                draw = draw.path_start() \
                           .path_move(to=(25, 0)) \
                           .path_elliptic_arc(to=(25, 50), radius=(15, 25)) \
                           .path_elliptic_arc(to=(0, -15), radius=(5, 5),
                                              clockwise=False, relative=True) \
                           .path_close() \
                           .path_finish()
                draw.draw(img)
                assert img[25, 35] == img[25, 20] == red
                assert img[15, 25] == img[30, 45] == blue
Exemplo n.º 44
0
def test_path_curve_to_quadratic_bezier_smooth():
    with nested(Color('#fff'),
                Color('#f00'),
                Color('#00f')) as (white, red, blue):
        with Image(width=50, height=50, background=white) as img:
            with Drawing() as draw:
                draw.fill_color = blue
                draw.stroke_color = red
                draw = (draw.path_start()
                        .path_curve_to_quadratic_bezier(to=(25, 25), control=(25, 25))
                        .path_curve_to_quadratic_bezier(to=( 10, -10), smooth=True, relative=True)
                        .path_curve_to_quadratic_bezier(to=( 35, 35), smooth=True, relative=False)
                        .path_curve_to_quadratic_bezier(to=(-10, -10), smooth=True, relative=True)
                        .path_finish())
                draw.draw(img)
                assert img[25,25] == red
                assert img[30,30] == blue
Exemplo n.º 45
0
def test_path_curve():
    with nested(Color('#fff'), Color('#f00'),
                Color('#00f')) as (white, red, blue):
        with Image(width=50, height=50, background=white) as img:
            with Drawing() as draw:
                draw.fill_color = blue
                draw.stroke_color = red
                draw = (draw.path_start().path_move(
                    to=(0, 25), relative=True).path_curve(
                        to=(25, 25), controls=((0, 0), (25, 0))).path_curve(
                            to=(25, 0),
                            controls=((0, 25), (25, 25)),
                            relative=True).path_finish())
                draw.draw(img)
                assert img[25, 25] == red
                assert img[35, 35] == img[35, 35] == blue
                assert img[35, 15] == img[15, 35] == white
Exemplo n.º 46
0
def make_overlay(a, b, outname):
    """Makes an overlay image of two key frames

    Using ImageMagick and the Wand python bindings
    """
    logger.debug("entering make_overlay with a: {},"
                 " b: {}, outname: {}".format(a, b, outname))
    bot = Image(filename=a)
    top = Image(filename=b)

    with nested(bot, top) as (b, t):
        t.transparentize(0.5)
        b.composite_channel(
            "all_channels", t, "dissolve",
            math.floor(b.width / 2) - math.floor(t.width / 2),
            math.floor(b.height / 2) - math.floor(t.height / 2))
        b.save(filename=outname)
    logger.debug("leaving make_overlay")
Exemplo n.º 47
0
def test_path_curve_to_quadratic_bezier_smooth():
    with nested(Color('#fff'), Color('#f00'),
                Color('#00f')) as (white, red, blue):
        with Image(width=50, height=50, background=white) as img:
            with Drawing() as draw:
                draw.fill_color = blue
                draw.stroke_color = red
                draw = (draw.path_start().path_curve_to_quadratic_bezier(
                    to=(25, 25),
                    control=(25, 25)).path_curve_to_quadratic_bezier(
                        to=(10, -10), smooth=True,
                        relative=True).path_curve_to_quadratic_bezier(
                            to=(35, 35), smooth=True,
                            relative=False).path_curve_to_quadratic_bezier(
                                to=(-10, -10), smooth=True,
                                relative=True).path_finish())
                draw.draw(img)
                assert img[25, 25] == red
                assert img[30, 30] == blue
Exemplo n.º 48
0
def test_draw_clip_path(display, fx_wand):
    with nested(Color('skyblue'), Color('orange')) as (skyblue, orange):
        with Image(width=100, height=100, background=skyblue) as img:
            fx_wand.push_defs()
            fx_wand.push_clip_path("eyes_only")
            fx_wand.push()
            fx_wand.rectangle(top=0, left=0, width=50, height=50)
            fx_wand.pop()
            fx_wand.pop_clip_path()
            fx_wand.pop_defs()

            fx_wand.clip_path = "eyes_only"
            fx_wand.clip_rule = "nonzero"
            fx_wand.clip_path_units = "object_bounding_box"
            fx_wand.fill_color = orange
            fx_wand.rectangle(top=5, left=5, width=90, height=90)
            fx_wand.draw(img)
            display(img)
            assert img[25, 25] == orange
            assert img[75, 75] == skyblue
Exemplo n.º 49
0
def test_draw_clip_path(display, fx_wand):
    with nested(Color('skyblue'),
                Color('orange')) as (skyblue, orange):
        with Image(width=100, height=100, background=skyblue) as img:
            fx_wand.push_defs()
            fx_wand.push_clip_path("eyes_only")
            fx_wand.push()
            fx_wand.rectangle(top=0,left=0, width=50, height=50)
            fx_wand.pop()
            fx_wand.pop_clip_path()
            fx_wand.pop_defs()

            fx_wand.clip_path = "eyes_only"
            fx_wand.clip_rule = "nonzero"
            fx_wand.clip_path_units = "object_bounding_box"
            fx_wand.fill_color = orange
            fx_wand.rectangle(top=5, left=5, width=90, height=90)
            fx_wand.draw(img)
            display(img)
            assert img[25, 25] == orange
            assert img[75, 75] == skyblue
Exemplo n.º 50
0
def test_draw_path_line():
    with nested(Color('#fff'),
                Color('#f00'),
                Color('#00f')) as (white, red, blue):
        with Image(width=50, height=50, background=white) as img:
            with Drawing() as draw:
                draw.fill_color = blue
                draw.stroke_color = red
                draw = (draw.path_start()
                        .path_move(to=( 5, 5))
                        .path_move(to=( 5, 5), relative=True)
                        .path_line(to=(40, 40))
                        .path_line(to=( 0,-10), relative=True)
                        .path_horizontal_line(x=45)
                        .path_vertical_line(y=25)
                        .path_horizontal_line(x=-5, relative=True)
                        .path_vertical_line(y=-5, relative=True)
                        .path_finish())
                draw.draw(img)
                assert img[40,40] == img[40,30] == red
                assert img[45,25] == img[40,20] == red
Exemplo n.º 51
0
def local_select():
    """
    Mesma coisa da função acima, para local no entanto
    """
    dimensions = {'width': 420, 'height': 150}
    with nested(Image(filename='ficha {}.png'.format(name)),
                Image(background=Color('transparent'), **dimensions)) as (img, shadow):
        with Drawing() as ctx:
            ctx.font = 'framd.ttf'
            ctx.fill_color = "black"
            ctx.font_size = 11.97
            ctx.text(34, 111, '{}'.format(local))
            ctx(shadow)
        shadow.gaussian_blur(1, 1)
        with Drawing() as draw:
            draw.font = 'framd.ttf'
            draw.fill_color = "rgb(255, 255, 255)"
            draw.font_size = 11.97
            draw.text(35, 111, '{}'.format(local))
            draw(shadow)
        img.composite(shadow, 0, 0)
        img.save(filename='ficha {}.png'.format(name))
from wand.color import Color
from wand.compat import nested
from wand.drawing import Drawing
from wand.image import Image

dimensions = {'width': 450, 'height': 100}

with nested(
        Image(filename=(
            '/home/linkgish/Desktop/WebApp2/GeneticDesignProject/example2.jpg'
        ),
              **dimensions),
        Image(background=Color('transparent'), **dimensions)) as (bg, shadow):
    # Draw the drop shadow
    with Drawing() as ctx:
        ctx.fill_color = Color('rgba(3, 3, 3, 0.6)')
        ctx.font_size = 64
        ctx.text(50, 75, 'Hello Wand!')
        ctx(shadow)
    # Apply filter
    shadow.gaussian_blur(4, 2)
    # Draw text
    with Drawing() as ctx:
        ctx.fill_color = Color('firebrick')
        ctx.font_size = 64
        ctx.text(48, 73, 'Hello Wand!')
        ctx(shadow)
    bg.composite(shadow, 0, 0)
    bg.save(
        filename=
        '/home/linkgish/Desktop/WebApp2/GeneticDesignProject/OutputWand.png')