Skip to content
Advertisement

What is text syntax in ImageMagick

I use following code convert text to image

convert -size 1000x100 xc:transparent -pointsize 30 -draw "text 0,30 'Text'" /tmp/test.png

what is x, y means in text x, y ‘string’?

Advertisement

Answer

Method 1 label:

You can either use label: which provides a canvas large enough to hold your text – notice I didn’t provide a canvas size:

convert -background yellow label:"This is somenmulti-line textnwhichnsurprisingly enough -nspans multiple lines" image.png

enter image description here

Method 2 -annotate

Or, you can use -annotate to write onto an outsize canvas, then -trim the canvas back to the minimum afterwards:

convert -size 1000x1000 xc:blue -pointsize 30 -gravity northwest -annotate 0 'Textnwith multiplenlines.' -trim result.png

enter image description here

When using -annotate, be sure to specify -gravity so that it positions according to the bounding box of your text, because if you do not, it will position according to the baseline (bottom-left corner) of your text.

Method 3 caption:

Or, you can use caption: which will size the text to best fit the box you provide:

convert -background pink -fill white -size 400x100 caption:"Here is a bunch of text that will be sized to best fit the box as far as is possible" result.png

enter image description here

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement