Multiple caption positioning

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
RocketR

Multiple caption positioning

Post by RocketR »

Hello, I'm struggling with this for already 2 days and without success.

I need to create an image which contains a title on top and a block of text that fits into specified area. I create title using 'label:' and text-block using 'caption:' but I don't know how to merge these parts together. It would be great to use '-draw text' but it can't create wrapped text!

The only solution I have found is to create an empty image of required size for background. Then create separate images for title and for text. Then merge them using 'composite'. But this sounds like there are too many steps for such a simple task. Is there a better way?
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Multiple caption positioning

Post by Bonzo »

Word wrap is a problem in all graphics programs.

Your solution sounds good and you can combine your background and title into one or does the title need to wordwrap?

Try:

Code: Select all

convert -size 100x100 -background none -fill black -font arial.ttf -pointsize 16 -gravity North caption:"Text" temp.png
convert -size 500x500 xc:lightblue -fill black -font arial.ttf -pointsize 16 -gravity North -annotate +0+0 "Title" temp.png -gravity West -composite output.png
Or:

Code: Select all

convert -size 500x500 xc:lightblue -fill black -font arial.ttf -pointsize 16 -gravity North -annotate +0+0 "Title" ( -size 100x100 -background none -fill white -pointsize 16 -gravity center caption:"Caption" -flatten ) -gravity West -composite output2.png
RocketR

Re: Multiple caption positioning

Post by RocketR »

Thank you, the first snippet works as expected!
The second shows some error, but it doesn't matter.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Multiple caption positioning

Post by anthony »

Have a look at Fred Weinhaus's script "autocaption"
http://www.fmwconcepts.com/imagemagick/ ... /index.php
Places text automatically in a specified square size region that has the least color variation.

Though I have not tried it and his examples uses the IM cartoon logo, which does not show a lot of 'variance' to thoroughly test the script. But it does sound like what you want.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Multiple caption positioning

Post by fmw42 »

also autolabel script in which you specify the color where the label or caption is to be placed and it finds the first large enough area
Post Reply