Text of differing sizes in separate lines

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?".
jamtat
Posts: 47
Joined: 2010-05-10T16:51:23-07:00
Authentication code: 8675308

Text of differing sizes in separate lines

Post by jamtat »

I've looked over the page http://www.imagemagick.org/Usage/text/ and it's got some really helpful tips for accomplishing what I'm trying to do. In brief, I want to create an image file that is only text, which I intend to place at the top of a whiteboard on which I will be wiriting/drawing for a screencast I'm doing. The image file will act as a sort of title, being overlain at the top of the whiteboard and forming an area which I will not be able to write/draw over.

I need two sizes of text in the image file I'm aiming to create: the first line should be really large text, with subsequent lines being smaller--maybe half as large as the main, title text. Using information I found at the page reference above, I was able to create a couple of image files that can work for my purposes--one containing the larger text on one line, and a separate image file containing the smaller text spanning two lines (width should be 830 pixels).

I can use those two image files, simply dragging them to the desired positions on the screen. But I wonder whether there might not be a way to get both the lines of smaller and the line of larger text into the same image file? So that I have only one image, instead of two, that I will need to position at the top of my whiteboard. My reading of the referenced page has not so far indicated to me a way of doing this, so I thought I'd ask here to see whether I might have overlooked something. Or is what I'm describing not possible to accomplish using IM?

PS I know I could, using, for example, a program like LO Draw, create a graphic of the sort I'm describing. But I would prefer, if possible, to create this from the command line.

User avatar
GeeMack
Posts: 757
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: Text of differing sizes in separate lines

Post by GeeMack »

jamtat wrote:I need two sizes of text in the image file I'm aiming to create: the first line should be really large text, with subsequent lines being smaller--maybe half as large as the main, title text. Using information I found at the page reference above, I was able to create a couple of image files that can work for my purposes--one containing the larger text on one line, and a separate image file containing the smaller text spanning two lines (width should be 830 pixels).
From the command line or batch script in Windows I can create a single JPG with two lines of different size text by appending two labels like this...

Code: Select all

convert ^
   -background white ^
   -bordercolor white ^
   -fill black ^
   -gravity center ^
   -pointsize 200 ^
   label:"This is 200 point text." ^
   -pointsize 100 ^
   label:"This is 100 point text." ^
   -append ^
   -border 20x20 ^
   -resize 830x ^
      output.jpg
You may need to use backslashes (or something else) instead of carets as escapes to make a multi-line command if you're not on a Windows system, or take out the carets and just make that all one line.

jamtat
Posts: 47
Joined: 2010-05-10T16:51:23-07:00
Authentication code: 8675308

Re: Text of differing sizes in separate lines

Post by jamtat »

Well, great work GeeMack. I should've mentioned this is on Linux. I stripped out the carets and made it a one-liner. The process seemed to stall for 10-20 seconds but then completed and the results look like pretty much just what I'm after. I'll have to examine the command more closely to see whether some other adjustments might need to be made to the command for my platform. Thanks for your help.

LATER EDIT: do I understand correctly that the font sizing can vary based on the amount of text contained in the labels? So, if the second label is a bit longish, rather than preserving text size the program will be trying to fit it all on one line, then resizing the whole so that it is no wider than 830 pixels? A further experiment I've done seems to indicate that this is how this solution works.

User avatar
fmw42
Posts: 26383
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Text of differing sizes in separate lines

Post by fmw42 »

If you want consistent font size, then use multiple calls to -annotate, each with different font sizes and different offsets. See http://www.imagemagick.org/Usage/text/#annotate

jamtat
Posts: 47
Joined: 2010-05-10T16:51:23-07:00
Authentication code: 8675308

Re: Text of differing sizes in separate lines

Post by jamtat »

I've done some experimentation with -annotate but am so far having only limited success. The problem is that the second line of text ends up being too wide to fit into the 830 pixel width specified. As a result, the last few words of that line end up getting cut off unceremoniously. Somehow the caption/label switches avoid this and introduce line breaks where sentence width exceeds the specified page width. Is there a way, without introducing line breaks manually, for this to happen when I use -annotate?

This command, for example, introduces a line break where the sentence exceed the width of the image:

Code: Select all

convert -background white -fill black -font Liberation-Sans-Bold -pointsize 24 -size 830x60 -gravity North caption:"Topics: A fairly lengthy sentence with words, various forms of punctuation, and so forth that exceeds the 830-pixel width specified" my-image.gif
PS I was wrong about the label switch doing line breaking: it does not. Further reading indicates to me that the caption switch is the one needed for non-manual line-breaking to work.

jamtat
Posts: 47
Joined: 2010-05-10T16:51:23-07:00
Authentication code: 8675308

Re: Text of differing sizes in separate lines

Post by jamtat »

Ok. Here's what's working for me:

Code: Select all

convert -background white -bordercolor white -fill black -gravity center -size 830x50 -pointsize 50 caption:"The screencast of the day" -size 830x55 -pointsize 25 caption:"Topics: For your viewing pleasure, all important events throughout the history of mankind will be covered, in ascending order, on this and on every other day of the week--time permitting" -append my-title.gif
So, I combined the first solution offered with what I'd already puzzled out about captions from reading and experimentation. One issue with this approach is that the "size" stipulation--and perhaps even the pointsize--will need to be adjusted for each screencast--dependent on the number of words/lines that will be contained in the second caption.

User avatar
fmw42
Posts: 26383
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Text of differing sizes in separate lines

Post by fmw42 »

With caption and label, the result will not have the specified points size, since they will fill the line to the size specified and adjust the pointsize appropriately. So do you really want to maintain point sizes or not? With -annotate, the pointsizes will be honored, but your image must be wide enough to support the width created by the pointsize.

jamtat
Posts: 47
Joined: 2010-05-10T16:51:23-07:00
Authentication code: 8675308

Re: Text of differing sizes in separate lines

Post by jamtat »

Ok, I think I'm understanding a bit better how this works, fmw42. Font sizing in the solution I found is acceptable and I'm not, within certain limits, after a particular pointsize. So it sounds like maybe I could just leave out the -pointsize stipulation in the incantation I came up with above, yes?

User avatar
fmw42
Posts: 26383
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Text of differing sizes in separate lines

Post by fmw42 »


alpha34
Posts: 5
Joined: 2016-11-20T05:05:39-07:00
Authentication code: 1151

Re: Text of differing sizes in separate lines

Post by alpha34 »

I have a similar requirement where I am creating a multiline logo that looks like the image here:

Image

How can I get rid of all the white space between each row?
How can I ensure that the width of the two letter logo in each row is the same while the height varies? You will notice that the smaller logos have white space padding on both sides (left & right) compared to the bigger logos. I would like this width to be the same across rows.

This is the command line script I currently have (to create this multiline logo):
magick ^
-background white -bordercolor white -fill green -gravity center ^
-size 160x160 -font Arial caption:"AB" ^
-size 160x120 -font Arial caption:"AW" ^
-size 160x80 -font Arial caption:"AX" ^
-size 160x40 -font Arial caption:"AX" ^
-size 160x20 -font Arial caption:"AX" ^
-append ^
output.jpg

User avatar
fmw42
Posts: 26383
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Text of differing sizes in separate lines

Post by fmw42 »

We cannot see your image? Did you use the img button? Did you put in a valid URL to your image?

You can adjust the spacing between lines using -interline-spacing and or adjust your height for each image?

To make the width the same across each row, you would likely need to use a fixed width font.

But it is hard to know what is going on, since we cannot view your image.

You might want to just use multiple instances of -annotate commands and adjust the spacing between each row with the -annotate +X+Y.

Please also always provide your IM version and platform (presumed windows from your syntax).

snibgo
Posts: 13034
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Text of differing sizes in separate lines

Post by snibgo »

Another possibility is "-trim" after the images, before the "-append". You could then, if you want, use "-resize" to make them all the same size.
snibgo's IM pages: im.snibgo.com

alpha34
Posts: 5
Joined: 2016-11-20T05:05:39-07:00
Authentication code: 1151

Re: Text of differing sizes in separate lines

Post by alpha34 »

fmw42 and snibgo,

Thank you for your suggestions. I will give them a try.
To see the image, Can you try going to this link: https://drive.google.com/open?id=0By1O5 ... WNXa2U5YlU

User avatar
fmw42
Posts: 26383
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Text of differing sizes in separate lines

Post by fmw42 »

OK, I can see your image now. But I do not know what it is that you want for output. Can you explain further with relationship to this image? What is wrong with it?

alpha34
Posts: 5
Joined: 2016-11-20T05:05:39-07:00
Authentication code: 1151

Re: Text of differing sizes in separate lines

Post by alpha34 »

fmw42, How can I ensure that the width of the two letter logo in each row is the same (while the height varies)? You will notice that the smaller logos have white space padding on both sides (left & right) compared to the bigger logos. I would like this width to be the same across rows.

Locked