Page 1 of 1

Annotation with differing font sizes?

Posted: 2016-08-15T11:00:42-07:00
by jamtat
These questions refer to IM version 6.9.5 runnning on a GNU/Linux system.

The scenario: a lightweight WM/desktop that uses a weather map, regularly updated throughout the day, as a desktop background. I set up this auto-refreshing desktop a few years ago, and it uses wget to download the map and IM to crop the map over a certain geographical area. A cron job runs at intervals to put the resulting map on the root window. It's been working great. I decided recently to enhance it somewhat by adding a bit of text to the map, text that contains some numerical weather values (current temperature, humidity, etc). I also use wget for that to downbload a text file, which I then parse with an awk script someone helped me cobble together.

I decided to use annotate to superimpose a few lines of text, in a certain location, over the weather map. I mainly appropriated the "fancy label" example found at http://www.imagemagick.org/Usage/annotating/. The results actually look pretty good, though I'm wondering about improving it a bit more. The improvement I have in mind is increasing the font size of one line of text, while reducing the font size in the other lines of text. What is of most interest to me is outside temperature, so I'd like to have that line in a very large font size, one I can read without my glasses. The other text could be a reduced size, since that information will not be so vital.

I currently have the text being added to the image in a single, rather lengthy command. I'd like, if possible, to stick with the one-liner approach. But from what I'm so far gathering, to do what I'm after, that is, to make the lines of text I'm superimposing have differing size fonts, I suspect I will be unable to use that approach. I think what I might need to do in order for this new scheme to work, will be to create of the lines of text a separate image, then to superimpose that image on the weather map image. So, am I right about that?

Here's a visual example of what I'm now doing: https://s3.postimg.io/tmi1tei2r/tmp_Desktopscrsht.png . What I'm aiming at is to have the temperature line in a font, say, at least twice the size of the time, conditions, and humidity lines. All lines are currently -pointsize 36. So maybe the pointsize for 3 lines could be reduced to pointsize 20, while the temperature line could be increased to 72 or something. What are the possible ways of doing something like this? Suggestions will be appreciated.

Re: Annotation with differing font sizes?

Posted: 2016-08-15T11:14:21-07:00
by snibgo
jamtat wrote:... create of the lines of text a separate image, then to superimpose that image on the weather map image. So, am I right about that?
That's how I would do it. Something like this (Windows BAT syntax; adjust for other shells):

Code: Select all

convert ^
  background_map.png ^
  ( ^
    -background None -fill Black ^
    -pointsize 30 label:"10:52 AM EDT" ^
    -pointsize 20 label:"mostly cloudy" ^
    -pointsize 70 label:"79.0 deg" ^
    -pointsize 20 label:"Humidity 62%" ^
    -gravity Center -append ^
  ) ^
  -compose Over -composite ^
  out.png
You can add shadow effects etc after "-gravity Center -append". You might also flatten over semi-transparent white.

Re: Annotation with differing font sizes?

Posted: 2016-08-15T11:43:04-07:00
by jamtat
Thanks for your response, snibgo. What I'm doing is pretty complex and I feared I might wind up leaving out some crucial detail or other. What you suggest would, of course, work, if the text being superimposed were to be static. But in my case, the text, like the weather map itself, changes throughout the day. Along with the changing map, the changing text gets downloaded using wget several times a day. I process it with awk to excise uneeded parts and to add line breaks, saving the results as a text file.

The content of that file winds up looking like 10:52 AM EDT\nmostly cloudy\n79.0 F\nHumidity :62% (\n is the line break signifier for the -annotate switch). When it comes time to superimpose that text onto the weather map, what I actually do is cat that content to the -annotate switch--something like -annotate 0 "$(cat /path/to/file.txt)".

Perhaps I could adapt your approach by somehow getting the pointsize values into the text file. I'll give that some further thought.

Re: Annotation with differing font sizes?

Posted: 2016-08-15T11:56:17-07:00
by snibgo
jamtat wrote:-annotate 0 "$(cat /path/to/file.txt)"
That won't work, to get different font sizes per line. For different sizes, you need further processing.

An easy way would be to read lines from that text file into shell variables (or single array) and use those in the "convert" command.

Alternatives include processing your text file to add Pango markup, or even SVG. Or, as you say, expanding you text file to include "-pointsize" etc.