Emma
Emma

Reputation: 470

Shaped shadows with wand

Are there functions equivalent to:

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

Which produces an 'A' with a blue shadow.

I have searched the docs thoroughly but couldn't find anything.
Is that just not possible yet?

Upvotes: 0

Views: 522

Answers (1)

emcconville
emcconville

Reputation: 24419

Not all CLI methods are present in the C-API library which integrates with. However, most behavior methods are straight forward (e.g. +swap), and you are free to implement them as your application sees fit.

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

Upvotes: 3

Related Questions