Page 1 of 1

Text to caption/pango with several font options

Posted: 2016-10-17T14:21:17-07:00
by perl
Hi,

I'm trying to make an image of several words (hundreds), which may be on a file (separated by spaces)

For that purpose I'm using this command (which works very well)

convert -background lightblue -fill blue -font justbeautifulsimplicity -gravity center -size 4500x3000 caption:@/tmp/list_of_words.txt out.png

But now I want to alternate some font properties for the words. For example, alternate foreground color like this:

Firstword(fgcolor=red) Secondword(fgcolor=blue) Thirdword(fgcolor=red) Fourthword(fgcolor=blue) and so on and so forth.

I tried to use pango format like this:

convert -background lightblue -fill blue -font justbeautifulsimplicity -gravity center -size 4500x3000 pango:@/tmp/somepangofile.txt out.png

and doig some <span foreground="red"> on the file.

So the color changing is working now, but the problem here is that the text is not justified and the font size is not selected according to the size of the image.

Is there a way to accomplish this?

Thanks in advance,
Best regards.

Re: Text to caption/pango with several font options

Posted: 2016-10-17T15:07:24-07:00
by snibgo
Use "-define pango:justify=true" for justifying both ends of the line. See http://www.imagemagick.org/Usage/text/#pango

Pango responds to "-gravity", though rather strangely. See my "Pango" page. It doesn't have a "auto font size" facility.

Re: Text to caption/pango with several font options

Posted: 2016-10-18T10:53:23-07:00
by perl
Thank you!

Definitely an improvement, but still It does not accomplish the same thing as caption.

Now the problem is that the font size is not automatically calculated for the given image size. Imagemagick with pango seems to choose a very small font size. With "caption", the font size was choosen automatically to fit image resolution and fullfill the image.

Is it possible to get the same with a pango file?

Re: Text to caption/pango with several font options

Posted: 2016-10-19T19:20:24-07:00
by anthony
No. Pango is a completely different system. Just a library that IM passes the request to.
You will need to specify the resolution and pointsize you want.

However. You can use caption, and then get IM to report the pointsize it chose for the current resoltion. IM generally saves discovered information in per-image properities, so that users can then make use of it later. Once you have the pointsize you can then map that into pango! It may not come out exactly the same (they aren't the same system) but it should be close.

Examples of getting the pointsize IM selected is shown in
IM Examples, Set and Per-Image Properties
http://www.imagemagick.org/Usage/basics/#set

The example is for label but it should be present for caption too.

Re: Text to caption/pango with several font options

Posted: 2016-10-21T10:00:09-07:00
by perl
That did the trick. As you said, It is not exact, but It is very close and indeed a good starting point.

Thank you so much!