python 魔杖:创建文本阴影
python wand: creating text dropshadow
有人试过用 python 魔杖创建阴影吗?我浏览了这个文档,但找不到 dropshadow 属性。
http://docs.wand-py.org/en/0.4.1/wand/drawing.html
根据 imagemagick 的说法,可以通过以下方式实现:
http://www.imagemagick.org/Usage/fonts/
convert -size 320x100 xc:lightblue -font Candice -pointsize 72 \
-fill black -draw "text 28,68 'Anthony'" \
-fill white -draw "text 25,65 'Anthony'" \
font_shadow.jpg
如何在 python 中进行调整?
Have anyone tried creating dropshadow with python wand?
如果您搜索 wand 标签,可以找到一些技巧和示例。
I went through this doc and couldn't find dropshadow attribute.
您不会看到属性,因为阴影在矢量绘图上下文中毫无意义。 (至少我认为)
这是创建文本阴影的一种途径/方法。
- 绘制阴影
- 应用过滤器(可选)
- 绘制文本
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(background=Color('skyblue'), **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='/tmp/out.png')
编辑这是另一个与用法示例相匹配的示例。
from wand.color import Color
from wand.drawing import Drawing
from wand.image import Image
# -size 320x100 xc:lightblue
with Image(width=320, height=100, background=Color('lightblue')) as image:
with Drawing() as draw:
# -font Candice
draw.font = 'Candice'
# -pointsize 72
draw.font_size = 72.0
draw.push()
# -fill black
draw.fill_color = Color('black')
# -draw "text 28,68 'Anthony'"
draw.text(28, 68, 'Anthony')
draw.pop()
draw.push()
# -fill white
draw.fill_color = Color('white')
# -draw "text 25,65 'Anthony'"
draw.text(25, 65, 'Anthony')
draw.pop()
draw(image)
# font_shadow.jpg
image.save(filename='font_shadow.jpg')
有人试过用 python 魔杖创建阴影吗?我浏览了这个文档,但找不到 dropshadow 属性。
http://docs.wand-py.org/en/0.4.1/wand/drawing.html
根据 imagemagick 的说法,可以通过以下方式实现: http://www.imagemagick.org/Usage/fonts/
convert -size 320x100 xc:lightblue -font Candice -pointsize 72 \
-fill black -draw "text 28,68 'Anthony'" \
-fill white -draw "text 25,65 'Anthony'" \
font_shadow.jpg
如何在 python 中进行调整?
Have anyone tried creating dropshadow with python wand?
如果您搜索 wand 标签,可以找到一些技巧和示例。
I went through this doc and couldn't find dropshadow attribute.
您不会看到属性,因为阴影在矢量绘图上下文中毫无意义。 (至少我认为)
这是创建文本阴影的一种途径/方法。
- 绘制阴影
- 应用过滤器(可选)
- 绘制文本
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(background=Color('skyblue'), **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='/tmp/out.png')
编辑这是另一个与用法示例相匹配的示例。
from wand.color import Color
from wand.drawing import Drawing
from wand.image import Image
# -size 320x100 xc:lightblue
with Image(width=320, height=100, background=Color('lightblue')) as image:
with Drawing() as draw:
# -font Candice
draw.font = 'Candice'
# -pointsize 72
draw.font_size = 72.0
draw.push()
# -fill black
draw.fill_color = Color('black')
# -draw "text 28,68 'Anthony'"
draw.text(28, 68, 'Anthony')
draw.pop()
draw.push()
# -fill white
draw.fill_color = Color('white')
# -draw "text 25,65 'Anthony'"
draw.text(25, 65, 'Anthony')
draw.pop()
draw(image)
# font_shadow.jpg
image.save(filename='font_shadow.jpg')