0

I would like to render justified text onto a transparent background, and save the result as png. It is important that the text should fit in a predefined rectangular box, and possibly fill it in, by automatically setting the font size and/or line and character spacing.

Which command line software should I use for this task?

1

Sounds like a case for ImageMagick – which usually even ships with the standard repositories of most Linux distributions. Your requirement is e.g. detailed here:

convert -size 300 -font Ubuntu -border 10 -bordercolor White -define pango:justify=true pango:"$(cat ./lorem.txt)" pango_justify.gif

They use GIF, but PNG (and many other formats) are supported as well. ImageMagick is the command-line tool when it comes to manipulating graphic files. There are many tutorials out there for it, too.

The package name to install it usually is imagemagick.

4
  • Very good, from a script I can try different fontsizes while examining the resulting image height, so the script can choose the most appropriate one.
    – Konstantin
    Aug 20 at 17:46
  • How can I achieve automatic hyphenation by defining the language of the text, or by setting the possible hyphenation points in some way?
    – Konstantin
    Aug 20 at 21:09
  • Sorry, I cannot help with how-tos on the topic (and asking that here would be off-topic anyhow). Shouldn't be too hard to find tutorials for, though, now that you know the right terms.
    – Izzy
    Aug 20 at 23:11
  • 1
    Yes, now I have found: you have to put '­' symbols into the text, at hyphenation points. And use a library, eg Ruby gem to hyphenate the text.
    – Konstantin
    Aug 20 at 23:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.