用魔杖塑造阴影

时间:2016-05-09 13:50:40

标签: python imagemagick python-3.5 wand

是否有相同的功能:

convert -background none -stroke black -fill white \
        -font Candice -pointsize 48 label:A -trim \
        \( +clone   -background navy   -shadow 80x3+3+3 \) +swap \
        -background none   -layers merge +repage  shadow_a.png

产生一个' A'带着蓝色的影子。

我彻底搜查了文档但却找不到任何内容 这是不可能的吗?

1 个答案:

答案 0 :(得分:3)

并非所有CLI方法都存在于集成的C-API库中。但是,大多数行为方法都是直截了当的(例如+swap),您可以根据应用程序的需要自由实现它们。

from wand.image import Image
from wand.color import Color
from wand.drawing import Drawing
from wand.compat import nested

with nested(Image(width=100, height=100, background=Color("transparent")),
            Image(width=100, height=100, background=Color("transparent"))) as (text,
                                                                               shadow):
    with Drawing() as ctx:
        ctx.stroke_color = Color("black")
        ctx.fill_color = Color("white")
        ctx.font_size = 48
        ctx.text(text.width/2, text.height/2, 'A')
        ctx(text)
    with Drawing() as ctx:
        ctx.fill_color = Color("navy")
        ctx.font_size = 48
        ctx.text(text.width/2, text.height/2, 'A')
        ctx(shadow)
    shadow.gaussian_blur(80, 3)
    shadow.composite(text, -3, -3)
    shadow.trim()
    shadow.save(filename='shadow_a.png')

Shaped shadow with wand