Imagemagick caption/label decapitates Å (A-ring)

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
User avatar
qubodup
Posts: 31
Joined: 2009-10-07T13:11:41-07:00
Authentication code: 8675309

Imagemagick caption/label decapitates Å (A-ring)

Post by qubodup »

Hello,

I'm trying to fill a certain area with variable text that will generate line breaks / word wrap. So I need captions. The variable text can contain all kinds of international names and titles.

Unfortunately, for example in "Å", the circle gets cut off.

Code: Select all

convert -background black -fill white -size 200x50 -gravity center label:"Åker" label.png
convert -background black -fill white -size 200x50 -gravity center caption:"Åker" caption.png
montage -label '%f' label.png caption.png -geometry +0+0 both.png
Image
I'm including label for curiosity.

Is this because Imagemagick doesn't automatically check the size needs of the used characters (can this be controlled)? Or is it the font's fault? Or just an Imagemagick bug?

I think I have read in the past, that it is recommended to render in a bigger area and then scale down but I can't remember where. Is there something in the documentation?

ImageMagick 6.9.5-2 Q16 x86_64 on Arch Linux
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Imagemagick caption/label decapitates Å (A-ring)

Post by snibgo »

Does your default font have that character? Check with:

Code: Select all

convert -background black -fill white -size 200x50 -gravity center label:"blah\nÅker\nblah" label.png
snibgo's IM pages: im.snibgo.com
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: Imagemagick caption/label decapitates Å (A-ring)

Post by GeeMack »

qubodup wrote:Unfortunately, for example in "Å", the circle gets cut off.
I use the Å character for scientific labels on thousands of images. Some fonts seem to render that character without a problem, but I use mostly monospace fonts and I always have to use some sort of workaround to prevent some or all of that little circle from getting chopped off. Mostly I end up putting a line break "\n" at the beginning of my caption...

Code: Select all

magick -font consolas -size 400x -pointsize 36 caption:"\nThis is Å test." output.png
... then trimming and bordering the result as needed.
User avatar
qubodup
Posts: 31
Joined: 2009-10-07T13:11:41-07:00
Authentication code: 8675309

Re: Imagemagick caption/label decapitates Å (A-ring)

Post by qubodup »

The character exists, I checked with

Code: Select all

convert -background black -fill white -size 100x100 -gravity center label:"Åker" check.png
Image

The \n method (inserting newline at beginning of each string) sounds good but might make space use very much less optimal. In my case, the strings are likely to use one, two or three lines and adding a newline changes up the aspect ratio (differently in each case)

I noticed the same issue happens with Umlaut Ä

Code: Select all

convert -background black -fill white -size 200x50 -gravity center label:"Äker" label.png
convert -background black -fill white -size 200x50 -gravity center caption:"Äker" caption.png
convert -background black -fill white -size 50x50 -gravity center label:"Äker" check.png
montage -label '%f' check.png label.png caption.png -geometry +0+0 all.png
Image
Is there a way to find out which font is being used by default?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Imagemagick caption/label decapitates Å (A-ring)

Post by fmw42 »

add -debug annotate. that should tell you the font being used.

Code: Select all

convert -debug annotate -background black -fill white -size 200x50 -gravity center label:"Äker" label.png
Returns for me:

Font /Library/Fonts/Arial.ttf .....
User avatar
qubodup
Posts: 31
Joined: 2009-10-07T13:11:41-07:00
Authentication code: 8675309

Re: Imagemagick caption/label decapitates Å (A-ring)

Post by qubodup »

Thanks!

Looks like my Linux installation uses Type1 by default (/usr/share/fonts/Type1/n019003l.pfb)

Code: Select all

convert -background black -fill white -size 200x50 -gravity center label:"Äker" -debug annotate label.png &> ok
This command returns many lines. Not sure if this is significant. Makes the impression of Imagemagick restarting multiple times:

Code: Select all

2016-07-16T05:44:20+02:00 0:00.050 0.030u 6.9.5 Annotate convert[11840]: annotate.c/RenderFreetype/1422/Annotate
  Font /usr/share/fonts/Type1/n019003l.pfb; font-encoding none; text-encoding none; pointsize 12
2016-07-16T05:44:20+02:00 0:00.050 0.030u 6.9.5 Annotate convert[11840]: annotate.c/GetTypeMetrics/844/Annotate
  Metrics: text: Äker; width: 25; height: 16; ascent: 9; descent: -3; max advance: 13; bounds: 0.828125,-0.046875  3.85938,7; origin: 25,0; pixels per em: 12,12; underline position: -2.35938; underline thickness: 0.78125
2016-07-16T05:44:20+02:00 0:00.070 0.050u 6.9.5 Annotate convert[11840]: annotate.c/RenderFreetype/1422/Annotate
  Font /usr/share/fonts/Type1/n019003l.pfb; font-encoding none; text-encoding none; pointsize 12
2016-07-16T05:44:20+02:00 0:00.070 0.060u 6.9.5 Annotate convert[11840]: annotate.c/GetTypeMetrics/844/Annotate
  Metrics: text: Äker; width: 25; height: 16; ascent: 9; descent: -3; max advance: 13; bounds: 0.828125,-0.046875  3.85938,7; origin: 25,0; pixels per em: 12,12; underline position: -2.35938; underline thickness: 0.78125
2016-07-16T05:44:20+02:00 0:00.080 0.070u 6.9.5 Annotate convert[11840]: annotate.c/RenderFreetype/1422/Annotate
  Font /usr/share/fonts/Type1/n019003l.pfb; font-encoding none; text-encoding none; pointsize 24
2016-07-16T05:44:20+02:00 0:00.090 0.080u 6.9.5 Annotate convert[11840]: annotate.c/GetTypeMetrics/844/Annotate
  Metrics: text: Äker; width: 49; height: 33; ascent: 18; descent: -6; max advance: 26; bounds: 1.65625,-0.5  7.70312,13; origin: 49,0; pixels per em: 24,24; underline position: -2.35938; underline thickness: 0.78125
2016-07-16T05:44:20+02:00 0:00.100 0.090u 6.9.5 Annotate convert[11840]: annotate.c/RenderFreetype/1422/Annotate
  Font /usr/share/fonts/Type1/n019003l.pfb; font-encoding none; text-encoding none; pointsize 48
2016-07-16T05:44:20+02:00 0:00.100 0.090u 6.9.5 Annotate convert[11840]: annotate.c/GetTypeMetrics/844/Annotate
  Metrics: text: Äker; width: 98; height: 66; ascent: 35; descent: -11; max advance: 53; bounds: 3.3125,-0.28125  15.4062,25.5; origin: 98,0; pixels per em: 48,48; underline position: -2.35938; underline thickness: 0.78125
2016-07-16T05:44:20+02:00 0:00.120 0.110u 6.9.5 Annotate convert[11840]: annotate.c/RenderFreetype/1422/Annotate
  Font /usr/share/fonts/Type1/n019003l.pfb; font-encoding none; text-encoding none; pointsize 96
2016-07-16T05:44:20+02:00 0:00.120 0.110u 6.9.5 Annotate convert[11840]: annotate.c/GetTypeMetrics/844/Annotate
  Metrics: text: Äker; width: 194; height: 132; ascent: 70; descent: -21; max advance: 105; bounds: 6.625,-2  30.8125,52; origin: 195,0; pixels per em: 96,96; underline position: -2.35938; underline thickness: 0.78125
2016-07-16T05:44:20+02:00 0:00.140 0.130u 6.9.5 Annotate convert[11840]: annotate.c/RenderFreetype/1422/Annotate
  Font /usr/share/fonts/Type1/n019003l.pfb; font-encoding none; text-encoding none; pointsize 192
2016-07-16T05:44:20+02:00 0:00.140 0.130u 6.9.5 Annotate convert[11840]: annotate.c/GetTypeMetrics/844/Annotate
  Metrics: text: Äker; width: 389; height: 264; ascent: 140; descent: -42; max advance: 210; bounds: 13.25,-4  61.625,104; origin: 391,0; pixels per em: 192,192; underline position: -2.35938; underline thickness: 0.78125
2016-07-16T05:44:20+02:00 0:00.150 0.140u 6.9.5 Annotate convert[11840]: annotate.c/RenderFreetype/1422/Annotate
  Font /usr/share/fonts/Type1/n019003l.pfb; font-encoding none; text-encoding none; pointsize 96.5
2016-07-16T05:44:20+02:00 0:00.160 0.150u 6.9.5 Annotate convert[11840]: annotate.c/GetTypeMetrics/844/Annotate
  Metrics: text: Äker; width: 195; height: 133; ascent: 71; descent: -22; max advance: 106; bounds: 6.65625,-2  30.9688,52; origin: 196,0; pixels per em: 97,97; underline position: -2.35938; underline thickness: 0.78125
2016-07-16T05:44:20+02:00 0:00.170 0.160u 6.9.5 Annotate convert[11840]: annotate.c/RenderFreetype/1422/Annotate
  Font /usr/share/fonts/Type1/n019003l.pfb; font-encoding none; text-encoding none; pointsize 48.5
2016-07-16T05:44:20+02:00 0:00.170 0.160u 6.9.5 Annotate convert[11840]: annotate.c/GetTypeMetrics/844/Annotate
  Metrics: text: Äker; width: 98; height: 67; ascent: 36; descent: -11; max advance: 53; bounds: 3.34375,-0.28125  15.5625,25.5; origin: 98,0; pixels per em: 49,49; underline position: -2.35938; underline thickness: 0.78125
2016-07-16T05:44:20+02:00 0:00.190 0.180u 6.9.5 Annotate convert[11840]: annotate.c/RenderFreetype/1422/Annotate
  Font /usr/share/fonts/Type1/n019003l.pfb; font-encoding none; text-encoding none; pointsize 72.5
2016-07-16T05:44:20+02:00 0:00.190 0.180u 6.9.5 Annotate convert[11840]: annotate.c/GetTypeMetrics/844/Annotate
  Metrics: text: Äker; width: 146; height: 100; ascent: 53; descent: -16; max advance: 79; bounds: 5,-2  23.2656,39; origin: 146,0; pixels per em: 73,73; underline position: -2.35938; underline thickness: 0.78125
2016-07-16T05:44:20+02:00 0:00.210 0.200u 6.9.5 Annotate convert[11840]: annotate.c/RenderFreetype/1422/Annotate
  Font /usr/share/fonts/Type1/n019003l.pfb; font-encoding none; text-encoding none; pointsize 60.5
2016-07-16T05:44:20+02:00 0:00.210 0.200u 6.9.5 Annotate convert[11840]: annotate.c/GetTypeMetrics/844/Annotate
  Metrics: text: Äker; width: 123; height: 83; ascent: 45; descent: -14; max advance: 66; bounds: 4.17188,-1  19.4219,33; origin: 123,0; pixels per em: 61,61; underline position: -2.35938; underline thickness: 0.78125
2016-07-16T05:44:20+02:00 0:00.220 0.210u 6.9.5 Annotate convert[11840]: annotate.c/RenderFreetype/1422/Annotate
  Font /usr/share/fonts/Type1/n019003l.pfb; font-encoding none; text-encoding none; pointsize 54.5
2016-07-16T05:44:20+02:00 0:00.230 0.220u 6.9.5 Annotate convert[11840]: annotate.c/GetTypeMetrics/844/Annotate
  Metrics: text: Äker; width: 110; height: 75; ascent: 40; descent: -12; max advance: 60; bounds: 3.76562,-1  17.5,30; origin: 110,0; pixels per em: 55,55; underline position: -2.35938; underline thickness: 0.78125
2016-07-16T05:44:20+02:00 0:00.240 0.230u 6.9.5 Annotate convert[11840]: annotate.c/RenderFreetype/1422/Annotate
  Font /usr/share/fonts/Type1/n019003l.pfb; font-encoding none; text-encoding none; pointsize 51.5
2016-07-16T05:44:20+02:00 0:00.240 0.230u 6.9.5 Annotate convert[11840]: annotate.c/GetTypeMetrics/844/Annotate
  Metrics: text: Äker; width: 105; height: 71; ascent: 38; descent: -12; max advance: 56; bounds: 3.54688,-1  16.5312,28; origin: 105,0; pixels per em: 52,52; underline position: -2.35938; underline thickness: 0.78125
2016-07-16T05:44:20+02:00 0:00.260 0.250u 6.9.5 Annotate convert[11840]: annotate.c/RenderFreetype/1422/Annotate
  Font /usr/share/fonts/Type1/n019003l.pfb; font-encoding none; text-encoding none; pointsize 50
2016-07-16T05:44:20+02:00 0:00.260 0.250u 6.9.5 Annotate convert[11840]: annotate.c/GetTypeMetrics/844/Annotate
  Metrics: text: Äker; width: 102; height: 69; ascent: 37; descent: -11; max advance: 55; bounds: 3.45312,-0.25  16.0469,27; origin: 102,0; pixels per em: 50,50; underline position: -2.35938; underline thickness: 0.78125
2016-07-16T05:44:20+02:00 0:00.280 0.270u 6.9.5 Annotate convert[11840]: annotate.c/RenderFreetype/1422/Annotate
  Font /usr/share/fonts/Type1/n019003l.pfb; font-encoding none; text-encoding none; pointsize 50.25
2016-07-16T05:44:20+02:00 0:00.280 0.270u 6.9.5 Annotate convert[11840]: annotate.c/GetTypeMetrics/844/Annotate
  Metrics: text: Äker; width: 103; height: 69; ascent: 37; descent: -11; max advance: 55; bounds: 3.46875,-0.25  16.125,27; origin: 103,0; pixels per em: 50,50; underline position: -2.35938; underline thickness: 0.78125
2016-07-16T05:44:20+02:00 0:00.290 0.280u 6.9.5 Annotate convert[11840]: annotate.c/RenderFreetype/1422/Annotate
  Font /usr/share/fonts/Type1/n019003l.pfb; font-encoding none; text-encoding none; pointsize 50.25
2016-07-16T05:44:20+02:00 0:00.300 0.290u 6.9.5 Annotate convert[11840]: annotate.c/GetTypeMetrics/844/Annotate
  Metrics: text: Äker; width: 103; height: 69; ascent: 37; descent: -11; max advance: 55; bounds: 3.46875,-0.25  16.125,27; origin: 103,0; pixels per em: 50,50; underline position: -2.35938; underline thickness: 0.78125
2016-07-16T05:44:20+02:00 0:00.310 0.300u 6.9.5 Annotate convert[11840]: annotate.c/RenderFreetype/1422/Annotate
  Font /usr/share/fonts/Type1/n019003l.pfb; font-encoding none; text-encoding none; pointsize 50.25
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Imagemagick caption/label decapitates Å (A-ring)

Post by fmw42 »

The many lines is due to IM iterating to find the best fit when you use label:

I do not know much about pfb fonts and their metrics. Most all my fonts are ttf.

But you could try specifying different fonts to see if other do not clip your accent marks.

On my system with your command:

Code: Select all

convert -background black -fill white -size 200x50 -gravity center label:"Äker" label.png
convert -background black -fill white -size 200x50 -gravity center caption:"Äker" caption.png
convert -background black -fill white -size 50x50 -gravity center label:"Äker" check.png
montage -label '%f' check.png label.png caption.png -geometry +0+0 all.png
And my default arial.tff, all the accent marks show up fine.

Image
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Imagemagick caption/label decapitates Å (A-ring)

Post by fmw42 »

What is your versions of freetype and fontconfig?

fontconfig @2.11.1_0
freetype @2.6.2_0

Code: Select all

convert -version

Version: ImageMagick 6.9.5-1 Q16 x86_64 2016-07-10 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2016 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Features: Cipher DPC Modules OpenMP 
Delegates (built-in): bzlib cairo fftw fontconfig freetype gslib jbig jng jp2 jpeg lcms lqr ltdl lzma openexr png ps rsvg tiff webp x xml zlib
User avatar
qubodup
Posts: 31
Joined: 2009-10-07T13:11:41-07:00
Authentication code: 8675309

Re: Imagemagick caption/label decapitates Å (A-ring)

Post by qubodup »

Thanks, fmw42. As you suggested, I did the following:

Code: Select all

find /usr/share/fonts/ -type f \( -name "*.ttf" -or -name "*.otf" \) > fonts

IFS=$'\r\n' content=($(cat fonts))

rm -r fonttestout
mkdir fonttestout

for ((idx = 0; idx < ${#content[@]}; idx+=1)); do
  font="${content[idx]}"
  name=`basename $font`
  echo $name

  convert -font "$font" -pointsize 72 label:"Å" -trim +repage fonttestout/"$name.png"
  exiftool -all= fonttestout/"$name.png" -overwrite_original > /dev/null
done
montage -fill white -label '%f' fonttestout/*png -background grey30 -gravity center -tile 3 -geometry +80+20 all.png
Output: http://i.imgur.com/fFiYC5D.png

Carlito, FreeSans, ipagp, ipamp, Roboto, RobotoCondensed cut off the o in Å

Cantarell, Carlito, DejaVuSans, DroidSerif, LeagueGothic, LiberationMono, LiberationSans, LiberationSerif, NotoSans, NotoSerif, OpenSans, Roboto, RobotoCondensed cut off the left end of an italic A.

DroidSansJapanese doesn't have that character at all - in a way different from arabic fonts etc. (might be normal).

Code: Select all

A Cantarell-BoldOblique.otf
A Cantarell-Oblique.otf
A Carlito-BoldItalic.ttf
A DejaVuSans-BoldOblique.ttf
A DejaVuSansCondensed-BoldOblique.ttf
A DejaVuSansCondensed-Oblique.ttf
A DejaVuSansMono-BoldOblique.ttf
A DejaVuSansMono-Oblique.ttf
A DejaVuSans-Oblique.ttf
A DejaVuSerif-BoldItalic.ttf
A DejaVuSerifCondensed-BoldItalic.ttf
A DejaVuSerifCondensed-Italic.ttf
A DejaVuSerif-Italic.ttf
A DroidSerif-BoldItalic.ttf
A DroidSerif-Italic.ttf
A LeagueGothic-CondensedItalic.otf
A LiberationMono-BoldItalic.ttf
A LiberationMono-Italic.ttf
A LiberationSans-Italic.ttf
A LiberationSerif-BoldItalic.ttf
A LiberationSerif-Italic.ttf
A NotoSans-BoldItalic.ttf
A NotoSans-Italic.ttf
A NotoSansUI-BoldItalic.ttf
A NotoSansUI-Italic.ttf
A NotoSerif-BoldItalic.ttf
A NotoSerif-Italic.ttf
A OpenSans-BoldItalic.ttf
A OpenSans-ExtraBoldItalic.ttf
A OpenSans-Italic.ttf
A OpenSans-LightItalic.ttf
A OpenSans-SemiboldItalic.ttf
_ DroidSansJapanese.ttf
oA Roboto-BlackItalic.ttf
oA Roboto-BoldItalic.ttf
oA RobotoCondensed-BoldItalic.ttf
oA RobotoCondensed-Italic.ttf
oA RobotoCondensed-LightItalic.ttf
oA Roboto-Italic.ttf
oA Roboto-LightItalic.ttf
oA Roboto-MediumItalic.ttf
oA Roboto-ThinItalic.ttf
o Carlito-Bold.ttf
o Carlito-Italic.ttf
o Carlito-Regular.ttf
o FreeSansBoldOblique.ttf
o FreeSansBold.ttf
o FreeSansOblique.ttf
o FreeSans.ttf
o ipagp.ttf
o ipamp.ttf
o Roboto-Black.ttf
o Roboto-Bold.ttf
o RobotoCondensed-Bold.ttf
o RobotoCondensed-Light.ttf
o RobotoCondensed-Regular.ttf
o Roboto-Light.ttf
o Roboto-Medium.ttf
o Roboto-Regular.ttf
o Roboto-Thin.ttf
I'm assuming this means that the fonts are at fault and the developers/designers/maintainers should be contacted.

Is there a way to tell Imagemagick that it should not take the font's information about how much space a glyph needs for granted and that it should assume that each glyph needs more space? Something like `-glyphpad 20x20`?

EDIT (didn't see the post):

Code: Select all

fontconfig 2.12.0-1
freetype2 2.6.5-1
Last edited by qubodup on 2016-07-20T22:47:40-07:00, edited 1 time in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Imagemagick caption/label decapitates Å (A-ring)

Post by fmw42 »

I would not know. It is a question more for the developers.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Imagemagick caption/label decapitates Å (A-ring)

Post by magick »

We are looking into this issue but so far have not found a robust solution. Spacing and offsets for caption / label are data driven by the font metrics. A glyphpad option may be the most promising solution. We will revisit this problem in about a week, we have other issues we're dealing with right now.
Post Reply