Page 1 of 1

Different fontsize for each line

Posted: 2015-01-13T15:57:20-07:00
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?

Re: Different fontsize for each line

Posted: 2015-01-13T16:08:54-07:00
by fmw42

Re: Different fontsize for each line

Posted: 2015-01-13T17:16:16-07:00
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.

Re: Different fontsize for each line

Posted: 2015-01-13T17:41:12-07:00
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

Re: Different fontsize for each line

Posted: 2015-01-13T19:28:07-07:00
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.

Re: Different fontsize for each line

Posted: 2015-01-14T01:30:23-07:00
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".

Re: Different fontsize for each line

Posted: 2015-01-14T10:50:36-07:00
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?

Re: Different fontsize for each line

Posted: 2015-01-14T10:52:04-07:00
by abs2act
snibgo - so that stacks the images together versus having just one image with both lines of text.

Re: Different fontsize for each line

Posted: 2015-01-14T11:05:12-07:00
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

Re: Different fontsize for each line

Posted: 2015-01-14T11:13:43-07:00
by fmw42
See my revised post above

Re: Different fontsize for each line

Posted: 2015-01-14T11:15:31-07:00
by abs2act
That's it! Thank you so much fmw42!!

Thanks to everyone else that replied. You guys rock!

Re: Different fontsize for each line

Posted: 2015-01-14T12:25:30-07:00
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.

Re: Different fontsize for each line

Posted: 2015-01-14T16:48:11-07:00
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

Re: Different fontsize for each line

Posted: 2015-01-15T10:10:43-07:00
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".