Question

I've got a bit of a weird question and, after parsing through ImageMagick's extensive documentation for hours, I cannot find an answer.

I have a program that creates text boxes within larger images. My current solution uses label: and caption: to create a temporary image sized appropriately, then later composites this image into the larger image. This has worked for me up until now.

convert \
    -size 321x93 \
    -font Carolyna-Pro-Black-Regular \
    -pointsize 43 \
    -fill #808080 \
    -gravity center \
    label:"Carolyna Pro Black\nis an obnoxious font." \
    /tmp/generator20140421-7999-157xadf.png

However, recently I added some new fonts, and these fonts are a pain to work with because they have rather large ascenders and descenders (loopy, curly bits above and below the text.) In the case of these fonts, these ascenders and descenders are supposed to overflow their bounding box. I've tried a few things, but none produce the desired effect:

  1. Making the bounding box larger: It seems like this would work, but when the -gravity is set to North, the text moves all the way to the top and clips the top anyway.
  2. Various forms of the -draw command: These don't give me the ability to use -gravity to align my text within the bounding box, and don't seem to work with multi-line text.
  3. Not specifying a -size argument and cropping the image later. This might be the only option, but it will take a lot of manual computation to get it to align text correctly, and adds an extra step to the process.

Essentially, my problem is that I need the text aligning capabilities that label: provides, but I don't want my text to be unnecessarily cut off.

Any ideas?

Was it helpful?

Solution

The solution turned out to be as simple as adding a newline character before and after the text, and adding the height of the text to the top and bottom of the bounding box.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top