0

How can I create such an image using imagemagick:

enter image description here enter image description here

That is, text on top of a solid-color background. The text's fill is not solid color but actually an image, as if the image is the background and the shape of the text has been cut out of the foreground solid fill.

I hope imagemagick has the capability to take as input at least

  • the background image
  • font to use
  • solid color to fill the rest with

and output an image like above.

Does anyone know how I can do so?

1
2

With some bits borrowed from an answer here and the imagemagick docs...

Creating the example text-background and image-background (any image would work, using solid colors here as a proof of concept):

convert -size 500x100 xc:dodgerblue -gravity center -background gold -extent 500x300 text_bg.png
convert -size 500x300 xc:red image_bg.png

text_bgimage_bg

Creating a text mask (black text on transparent background):

convert -background none -font /usr/share/fonts/TTF/TerminusTTF-Bold.ttf -pointsize 60\
-fill black label:'Test Mask Text' -rotate 25 -gravity center -extent 500x300 text.png

text.png

And now to composite the three:

convert image_bg.png text_bg.png text.png -composite comp.png

comp.png

2
  • Which ImageMagick version/s did you use for this? When I try with 6.8.9-9 (and include the missing filename in the first step), the end result is solid red; I need to set the text background to white (rather than none/transparent) for it to work as a mask in the composite step.
    – JigglyNaga
    Feb 13 '20 at 11:22
  • @JigglyNaga Interesting, and thanks for pointing out the missing filename. I'm on Version: ImageMagick 7.0.9-13
    – Egon
    Feb 13 '20 at 17:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.