Add Auto sized text to rectangle area of image

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?".
kevinleesmith
Posts: 20
Joined: 2014-10-17T03:12:47-07:00
Authentication code: 6789

Re: Add Auto sized text to rectangle area of image

Post by kevinleesmith »

Aha - bingo - Now I understand as %1 etc is using on BAT scripts for parameter passing. I remove the double % and its fine now.
Many many thanks.
kevinleesmith
Posts: 20
Joined: 2014-10-17T03:12:47-07:00
Authentication code: 6789

Re: Add Auto sized text to rectangle area of image

Post by kevinleesmith »

Thanks - that did the trick - i did send this message yesterday but I just came here to post another comment and my comment thanking you from yesterday is not here!!! (second time that happened)

Anyway,

Everything looks fine apart from a couple of things that are not quite right in relation to the size of the text.

The good
This one has a lot of text and is sized correctly to fill: http://www.pragmaticea.com/PF2/componen ... 000276.png
This one has a small amount of text and is sized correctly to fill: http://www.pragmaticea.com/PF2/componen ... 000526.png

The bad (maybe it sizes the text and stops when it cannot go bigger without a word fitting on 1 line?
http://www.pragmaticea.com/PF2/componen ... 000470.png

The ugly
You can see all images I have produced and the resulting variation in success/failure of the text to be scaled to fit here (warning - this html will try to load 300+ images): www.peaf.com/images/temp.htm
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Add Auto sized text to rectangle area of image

Post by snibgo »

wrote:The bad (maybe it sizes the text and stops when it cannot go bigger without a word fitting on 1 line?
http://www.pragmaticea.com/PF2/componen ... 000470.png
What is bad about that? The text cannot be larger, as you say. Would you prefer it smaller?

IM records the pointsize it used in property "caption:pointsize:", so you can re-run with an explicit pointsize that is, say, 80% of the recorded value.
snibgo's IM pages: im.snibgo.com
kevinleesmith
Posts: 20
Joined: 2014-10-17T03:12:47-07:00
Authentication code: 6789

Re: Add Auto sized text to rectangle area of image

Post by kevinleesmith »

Yes I figured out what it was doing while I was writing that, which, as you say, is reasonable.

Maybe an enhacement request then - for IM to split words and insert a hyphen to break words so it can maximise the text size within an area?

I'm not griping though I already donated $50 to them.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Add Auto sized text to rectangle area of image

Post by snibgo »

Hyphenation would be a useful enhancement. However, it requires a dictionary of words marked with all possible hyphenation points, and one dictionary is required per language, and we would need to tell IM what language is being used.

For that, more specialist typography software might be needed.
snibgo's IM pages: im.snibgo.com
kevinleesmith
Posts: 20
Joined: 2014-10-17T03:12:47-07:00
Authentication code: 6789

Re: Add Auto sized text to rectangle area of image

Post by kevinleesmith »

True.

One last question to finish this post - Can I change the blue background to a diagonal gradient fill from dark blue to lighter blue? I've looked through the docs and found https://imagemagick.org/script/gradient.php but not sure how to apply that to my blue box
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Add Auto sized text to rectangle area of image

Post by snibgo »

I would do that by writing the text with "-background None", which means transparent. Clone this, and make that image the gradient. Composite the text image over the gradient image. Then append that to the input image.

Code: Select all

%IMG7%magick ^
  testing2.png ^
  -size 200x%%[fx:h] ^
  -background None ^
  caption:"This is some text that could be of any length which should be made as big as possible to fill the box" ^
  ( +clone ^
    -sparse-color bilinear "0,0,#00f,%%[fx:w-1],%%[fx:h-1],#88f" ^
  ) ^
  ( -clone 1,2 ^
    -compose DstOver -composite ^
  ) ^
  -delete 1,2 ^
  +append ^
  capt-right2.png
snibgo's IM pages: im.snibgo.com
kevinleesmith
Posts: 20
Joined: 2014-10-17T03:12:47-07:00
Authentication code: 6789

Re: Add Auto sized text to rectangle area of image

Post by kevinleesmith »

Coll - many thanks. Its really a programming environment in its own right. Could be useful to have an IDE that churns out the code required.
Post Reply