0

imagemagick convert:

how to write text with different font size on the same baseline?

I want something like this: enter image description here

hrlinc
  • 33
  • 5

1 Answers1

2

You can get the font metrics like this:

convert -debug annotate -pointsize 12 label:"Apple" info:

Output

enter image description here

If you want to mix 24pt, 36pt and 48pt font sizes, you will need to run it three times - once for each font size.

If you change the pointsize, you will see that the height and descent change accordingly. You will need to pad the bottom edge of the smaller fonts with some number of pixels to make them align with the bigger fonts. That number is related to the fields height and descent - I think it is just height-abs(descent) but I have not tested extensively.

When you have the padding, you can line them up like this:

convert -gravity south \
     -pointsize 24 label:"Apple" -splice x5    \
  \( -pointsize 36 label:"Apple" -splice x2 \) \
     -pointsize 48 label:"Apple" +append result.jpg

enter image description here

So, I spliced on 5 pixels to the bottom of the 24pt text and 2 pixels to the bottom of the 24pt text to line them up with the 36pt text - and the bottoms are aligned because I set -gravity south.

Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
  • is there any way to do this with javascript or on the front end of programming languages in general? – oldboy Oct 07 '20 at 05:03