text height

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
immortal26

text height

Post by immortal26 »

Hello all,

First off here is the code in php (via command):

Code: Select all

$compolay = 'convert  -size 1145x408\!  -rotate 180 -distort Arc "45, 150"  -gravity center -background none -fill "#FFFFFF40" -font '.$font.' label:"'.$text.'"  comp.png';
I'm wanting to keep the width so label can automatically resize the text to fit that width but I also know that it controls the pointsize of the font. So basically what I'm trying to do is let it keep doing what it's doing with the width but also i want it to ignore the aspect ratio of the width and give me the height I'm trying to put in... as in stretch the text up at the width given and height given.

Thanks
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: text height

Post by snibgo »

As far as I know, label etc can't stretch the text height. But you can stretch the text afterwards. For example, to fit text exactly into 500x500 (Windows script):

Code: Select all

convert ^
  -size 500x500 label:"Hello world" ^
  -trim +repage -resize "500x500^!" ^
  text.png
snibgo's IM pages: im.snibgo.com
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: text height

Post by anthony »

WARNING Brain dump in progress... Content may be a little muddled, and off topic

text rendering does not make use of any aspect ratio settings (except posibly in -draw with canvas warping)
It just generates a 1:1 ratio as described by the font.

Of course fonts are not all the same height at a specific pointsize. Pointsize actually refers to 'line spacing' and not anything to do with the actual draw text, whcih is why I find so many fonts very small when compared with other fonts.

If you decide to resize the height (rather than pad it with -extent) make sure you include a '!' flag or resize also preserves the aspect ratio.

I would suggest you trim the label after you generate it a a specific width. pad the label width back to normal (-extent), perhaps add a small border for to space it a little from the trimmed edges, before resizing the height appropriately.

Exactly what you do however is up to you.

NOTE for a better quality with resizing. Create the label at a larger -density, Say twice the density and twice the width. Do the trim/pad/border stuff. then shrink the whole thing down to the actual final size.

Note I did not say double the pointsize but double the density. The two behave slightly differently with some fonts, though they have similar size effects.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply