Reputation: 111
Have anyone tried creating dropshadow with python wand? I went through this doc and couldn't find dropshadow attribute.
http://docs.wand-py.org/en/0.4.1/wand/drawing.html
According to imagemagick it is possible by doing below: 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
How can I adapt this in python?
Upvotes: 1
Views: 2668
Reputation: 24439
Have anyone tried creating dropshadow with python wand?
There's a few techniques, and examples if you search the wand tag.
I went through this doc and couldn't find dropshadow attribute.
You would not see an attribute, as the dropshadow is nonsensical in vector drawing context. (at least I think)
Here's one approach / method for creating text dropshadows.
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')
Edit Here's another example that matches the Usage example.
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')
Upvotes: 5