How to justify text in ImageMagick?

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?".
Post Reply
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to justify text in ImageMagick?

Post by fmw42 »

xerenader wrote:I'm just curious if there is any command line for justified text in IM.

I believe that -annotate respects the -gravity setting and -annotate +X+Y are relative to the gravity.

I believe that -draw also respects the -gravity setting.

see http://www.imagemagick.org/Usage/text/
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: How to justify text in ImageMagick?

Post by anthony »

Yes Gravity and Justification are currently the same thing in IMv6

One item on my IMv7 ToDo list, is to actually separate Gravity placement, verses Justification.
Not only for text, but also for placement of images during composition.

Justification is part of the SVG drawing, even though gravity is not.
It should be made part of MVG -draw settings as well.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: How to justify text in ImageMagick?

Post by anthony »

Yes. but as gravity is involved it depends on exactly what you are trying to do.
So give us an example of what you actually want, and we'll be able to tell you more.

And look through the link already given above.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: How to justify text in ImageMagick?

Post by anthony »

First I suggest you re-think the order of your operations.

-resample for example is an operator that works on an actual image! As such it at least should be AFTER the caption:

Also -density and -resample combination is not really required for caption, but for postscript pdf and other vector images. Text drawing is handles find without needing them.

The same goes for -rotate 0 which actually does nothing!

Simplifying the problem....

Code: Select all

   convert -gravity west -size 100x \
            caption:"This is a long sentance that should need word-wrapping" \
            text_caption.png
Image

Code: Select all

   convert -gravity east -size 100x \
            caption:"This is a long sentance that should need word-wrapping" \
            text_caption_east.png
Image

Code: Select all

   convert -gravity north -size 100x \
            caption:"This is a long sentance that should need word-wrapping" \
            text_caption_north.png
Image
Well that shows that the caption is handling the 'gravity' justification setting appropriately.

Vertically too if you 'fix' the optional height of the caption box size.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply