gpt4 book ai didi

python 魔杖 : creating text dropshadow

转载 作者:太空宇宙 更新时间:2023-11-04 08:49:05 24 4
gpt4 key购买 nike

有没有人试过用 python wand 创建阴影?我浏览了这个文档,找不到 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?

如果您搜索 ,可以找到一些技巧和示例标签。

I went through this doc and couldn't find dropshadow attribute.

不会看到属性,因为阴影在矢量绘图上下文中毫无意义。 (至少我认为)

这是创建文本阴影的一种方法。

  1. 画阴影
  2. 应用过滤器(可选)
  3. 绘制文字
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')

Creating Text dropshadow

编辑这是另一个与用法示例相匹配的示例。

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')

font_shadow.jpg

关于 python 魔杖 : creating text dropshadow,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37295566/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com