Certain fonts get cut off

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?".
Locked
roallen
Posts: 5
Joined: 2020-01-14T05:37:20-07:00
Authentication code: 1152

Certain fonts get cut off

Post by roallen »

Certain script fonts get cut off. Is there any way to solve this that works regardless of the font being used?

Code: Select all

magick -size 600x -font KaushanScript-Regular.ttf -fill '#000' label:'Cutoff' cutoff.png
Here is the font in this example but I've seen it happen with others too:
https://fonts.google.com/specimen/Kaushan+Script

Image

Thank you!
Robbie

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

Re: Certain fonts get cut off

Post by snibgo »

I don't now what creates the problem.

As a workaround, you can use "\n" and spaces to create padding. Then trim, and perhaps add a border, if you want.

Code: Select all

label:'\n  Cutoff  \n'
snibgo's IM pages: im.snibgo.com

User avatar
magick
Site Admin
Posts: 11254
Joined: 2003-05-31T11:32:55-07:00

Re: Certain fonts get cut off

Post by magick »

Thanks for the problem report. We can reproduce it and will have a patch to fix it in GIT master branch @ https://github.com/ImageMagick/ImageMagick later today. The patch will be available in the beta releases of ImageMagick @ https://www.imagemagick.org/download/beta/ by sometime tomorrow.

roallen
Posts: 5
Joined: 2020-01-14T05:37:20-07:00
Authentication code: 1152

Re: Certain fonts get cut off

Post by roallen »

Cool! I can also generate images where it cuts off the top of letters. Will the same patch fix that too? Thank you!!

User avatar
magick
Site Admin
Posts: 11254
Joined: 2003-05-31T11:32:55-07:00

Re: Certain fonts get cut off

Post by magick »

No. Post a command-line with letters cut-off that we can reproduce and we'll try to fix both problems.

roallen
Posts: 5
Joined: 2020-01-14T05:37:20-07:00
Authentication code: 1152

Re: Certain fonts get cut off

Post by roallen »

This one is a little more complicated. I need to able to produce an image with two words. In some cases those words may use the same font and in other cases they may not. This turned out to be harder than I hoped because Imagemagick doesn't natively create a common baseline to sit both words on top of.

This command:

Code: Select all

/usr/local/bin/magick -size x100 \( -font Pacifico-Regular.ttf label:'Image ' \) \( -font Poppins-Regular.ttf label:'Magick' \) +append test.png
Produces this:
Image

To fix this, I found this pretty ugly workaround:

Code: Select all

/usr/local/bin/magick -size 1560x1200 -density 100 \( xc:none -fill blue -draw 'line 15,0 15,99' -undercolor white -fill '#000000' \( -clone 0 -font Pacifico-Regular.ttf -pointsize 72 -annotate +5+80 'Image ' \)  \( -clone 0 -font Poppins-Regular.ttf -pointsize 72 -annotate +5+80 'Magick ' \)  -delete 0 -trim +repage +append -transparent blue -trim +repage -background white -flatten -resize 500x \)  test.png
Produces this:
Image

Chops off the top a bit and does even worse with just script font:
Image

In messing around, if I removed the "-density" parameter, it seems to fix it.
Image

Are there any better options?

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

Re: Certain fonts get cut off

Post by snibgo »

To combine multiple fonts, you might use pango. For example, Windows syntax:

Code: Select all

magick ^
  -pointsize 30 ^
  pango:"Face: <span face='Arial'>Arial</span> <span face='Verdana'>Verdana</span> <span face='Times new roman'>Times new roman</span> <span face='Courier'>Courier</span>" ^
  pangofont.png
Image
snibgo's IM pages: im.snibgo.com

Locked