wand
wand copied to clipboard
Create and operate on a label: generated image
I have a set of ImageMagick commands which I am attempting to convert to the Wand equivalents, and I am having trouble replicating this. The goal of the image is to add some text with a drop shadow to an image.
My commands (with all the unnecessary operations removed) are as follows:
magick in.jpg -size 3200x1800 \
\( -pointsize 100 -fill white label:"Example" \
\( +clone -background "black" -shadow 95x3+10+10 \) \
+swap -background none -layers merge +repage \
\) -geometry +100+100 -composite \
out.jpg
My Wand implementation is as follows:
from wand.drawing import Drawing
from wand.image import Image
with Image(filename='in.jpg') as img:
img.resize(3200, 1800)
with Image() as label:
with Drawing() as draw:
draw.font_size = 100
draw.text(0, 0, 'Example')
draw(label)
shadow = label.clone()
shadow.background_color = 'black'
shadow.shadow(95, 3, 10, 10)
label.sequence.append(shadow)
label.sequence.append(label.sequence.pop(0))
label.transparent_color('none')
label.merge_layers('merge')
label.trim()
label.reset_coords()
img.composite(label, left=100, top=100)
img.save(filename='out.jpg')
However, this gives an exception on label.clone()
of
wand.exceptions.WandError: wand contains no images `MagickWand-10' @ error/magick-image.c/MagickDrawImage/3093
When I'd expect the drawing (text) to be placed onto the image (label).
Thanks!