Different fontsize for each line

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
abs2act
Posts: 10
Joined: 2014-08-12T20:41:45-07:00
Authentication code: 6789

Different fontsize for each line

Post by abs2act »

I'm trying to create labels with different font sizes for each line.

E.g.

Code: Select all

convert -background black -fill white -size 720x480 -pointsize 50 -gravity NorthWest -font Roboto-Regular label:'TEST1\nTEST2' -extent 720x480-70+0 test.png
I would like to increase the pointsize for TEST2 to lets say 60. Any ideas?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Different fontsize for each line

Post by fmw42 »

abs2act
Posts: 10
Joined: 2014-08-12T20:41:45-07:00
Authentication code: 6789

Re: Different fontsize for each line

Post by abs2act »

Thanks fmw42 for the links.

So the image doesn't turn out the way I exactly want. For example:

Code: Select all

convert -background black -fill white -size 720x480 -gravity NorthWest \
-font Roboto-Regular -pointsize 30 label:'TEST1' \
-font Roboto-Regular -pointsize 35 label:'TEST2' \
+append test.png
This creates 2 images and combines it. I want 1 image with TEST1 in the first line and TEST2 in a the second line with a different pointsize.

Something like this

Code: Select all

convert -background black -fill white -size 720x480 -gravity NorthWest \
-font Roboto-Regular -pointsize 30 label:'TEST1'\nTEST2' \
test.png
Unfortunately I can't figure out a way to change TEST2 to pointsize 35.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Different fontsize for each line

Post by anthony »

You could look at using Pango, which lets you add meta tags in the text to format it. However it has less control over font selection.

http://www.imagemagick.org/Usage/text/#pango
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Different fontsize for each line

Post by fmw42 »

Thanks fmw42 for the links.

So the image doesn't turn out the way I exactly want. For example:
Note that label: and caption: are to create new images and then overlay them on a background image.

However, with -draw, you can put all the arguments into one -draw command and write directly to some background image.

Alternately, you can make several calls to -annotate to write each line to some background image.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Different fontsize for each line

Post by snibgo »

abs2act wrote:I want 1 image with TEST1 in the first line and TEST2 in a the second line with a different pointsize.
Use "-append" instead of "+append".
snibgo's IM pages: im.snibgo.com
abs2act
Posts: 10
Joined: 2014-08-12T20:41:45-07:00
Authentication code: 6789

Re: Different fontsize for each line

Post by abs2act »

fmw42 - I see you what you're saying. Can you provide an example of how to use the -draw command with the context I've provided?
abs2act
Posts: 10
Joined: 2014-08-12T20:41:45-07:00
Authentication code: 6789

Re: Different fontsize for each line

Post by abs2act »

snibgo - so that stacks the images together versus having just one image with both lines of text.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Different fontsize for each line

Post by fmw42 »

abs2act wrote:fmw42 - I see you what you're saying. Can you provide an example of how to use the -draw command with the context I've provided?

unix syntax (new line == \) in windows use (new line == ^)

Code: Select all

convert -size 720x480 xc:black -fill white -font Arial \
-draw "font-size 30 text 0,30 'TEST1' font-size 35 text 0,65 'TEST2'" result.png
Or use draw twice

Code: Select all

convert -size 720x480 xc:black -fill white -font Arial \
-pointsize 30 -draw "text 0,30 'TEST1'" \
-pointsize 35 -draw "text 0,65 'TEST2'" result.png
The text x,y y value needs to allow space for the pointsize (font-size) and for any space between the top and bottom text.


Or use annotate twice

Code: Select all

convert -size 720x480 xc:black -fill white -font Arial \
-pointsize 30 -annotate +0+30 "TEST1" \
-pointsize 35 -annotate +0+65 "TEST2" result.png
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Different fontsize for each line

Post by fmw42 »

See my revised post above
abs2act
Posts: 10
Joined: 2014-08-12T20:41:45-07:00
Authentication code: 6789

Re: Different fontsize for each line

Post by abs2act »

That's it! Thank you so much fmw42!!

Thanks to everyone else that replied. You guys rock!
abs2act
Posts: 10
Joined: 2014-08-12T20:41:45-07:00
Authentication code: 6789

Re: Different fontsize for each line

Post by abs2act »

One last thing. So I'm trying to shift the lines x pixels over. Here's my code.

Code: Select all

convert -size 720x480 xc:black -fill white -font Arial \
-pointsize 30 -annotate +0+30 "TEST1" \
-pointsize 35 -annotate +0+65 "TEST2" \
-extent 720x480-50+0 result.png
The lines shift but for some reason I get a white bar on the left. I want the background to stay black.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Different fontsize for each line

Post by fmw42 »

So I'm trying to shift the lines x pixels over.
Just modify the +0 after annotate, that is the x offset from whatever -gravity you have set, which by default is northwest.

-annotate +Xoff+Yoff "your text"


So

Code: Select all

convert -size 720x480 xc:black -fill white -font Arial \
-pointsize 30 -annotate +50+30 "TEST1" \
-pointsize 35 -annotate +50+65 "TEST2" \
result.png
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Different fontsize for each line

Post by snibgo »

abs2act wrote:The lines shift but for some reason I get a white bar on the left. I want the background to stay black.
The white stripe comes from "-extent", which pads using the background colour. See http://www.imagemagick.org/script/comma ... php#extent . The default background colour is white. Set it to whatever you want before "-extent".
snibgo's IM pages: im.snibgo.com
Post Reply