简短回答:潘戈

简短回答:潘戈

我正在尝试使用创建许多单字符图像convert。目的是为塑料专家提供可打印到键盘键帽上的图像。

ImageMagick 文档建议这样的事情:

 printf "\u2318" | convert -size 100x100 label:@- -font unifont-Medium command.png

或者

 echo ⌘ | convert -size 100x100 label:@- -font unifont-Medium command.png

或者

 convert -size 100x100 label:'⌘' -font unifont-Medium command.png

应该打印景点符号,但它会产生一个问号。

我已经确认(使用charmapunifont-Medium字体集实际上包含这个字形。我知道我系统上的其他字体也可以提供这个字形,因为我可以在安装 unifont 之前看到它,但我无法弄清楚它们的名字是什么。

我还尝试使用 LaTeX(例如带有所有附加功能和utf8x软件包的 TexLive),但不支持任何特殊字符。

有很多关于用 imagemagick 和其他特殊字符打印汉字的论坛问题......以下对我有用:

convert -background lightblue -fill blue -pointsize 32 \
      label:' é è à ù ç Ö ÿ ‘ ’ “ ” ° ² ³ € x ÷ '    label_i8n.gif

但它不适用于对我来说实际上很重要的 UTF-8 字符。

如何将任意 unicode 字符转换为图像?

更新: 我放弃了,看起来像个bug。相反,我创建了一堆脚本来生成和渲染 SVG,在此处开源:运动德沃夏克

答案1

我尝试了相同的命令并得到了相同的结果。

$ printf "\u2318" | convert -size 100x100 label:@- \
        -font unifont-Medium command.png

                                                                           渲染字体的 ss

不过,更改为字母 G 的 unicode 效果很好:

$ printf "\u0047" | convert -size 100x100 label:@- \
       -font unifont-Medium command.png

                                                                           G

我会将这个问题发布到ImageMagick 讨论站点看看为什么会发生这种情况。如果您不确定如何执行此操作或继续,我可以提供帮助。

调试转换

您可以添加-debug annotate开关来查看convert最新情况。

例子

$ printf "\u2318" | convert -size 100x100 label:@- -font unifont-Medium -pointsize 40 -debug annotate command.png
2014-04-10T09:37:04-04:00 0:00.020 0.010u 6.7.8 Annotate convert[16619]: annotate.c/RenderFreetype/1220/Annotate
  Font /usr/share/fonts/msttcorefonts/arialbd.ttf; font-encoding none; text-encoding none; pointsize 12
2014-04-10T09:37:04-04:00 0:00.020 0.010u 6.7.8 Annotate convert[16619]: annotate.c/GetTypeMetrics/798/Annotate
  Metrics: text: ⌘; width: 6.375; height: 14; ascent: 11; descent: -3; max advance: 24; bounds: 0.625,0  6.78125,8; origin: 7,0; pixels per em: 12,12; underline position: -5.0625; underline thickness: 3.35938
2014-04-10T09:37:04-04:00 0:00.020 0.010u 6.7.8 Annotate convert[16619]: annotate.c/RenderFreetype/1220/Annotate
  Font /usr/share/fonts/msttcorefonts/arialbd.ttf; font-encoding none; text-encoding none; pointsize 12
2014-04-10T09:37:04-04:00 0:00.020 0.010u 6.7.8 Annotate convert[16619]: annotate.c/GetTypeMetrics/798/Annotate
  Metrics: text: ⌘; width: 6.375; height: 14; ascent: 11; descent: -3; max advance: 24; bounds: 0.625,0  6.78125,8; origin: 7,0; pixels per em: 12,12; underline position: -5.0625; underline thickness: 3.35938
2014-04-10T09:37:04-04:00 0:00.020 0.010u 6.7.8 Annotate convert[16619]: annotate.c/RenderFreetype/1220/Annotate
  Font /usr/share/fonts/msttcorefonts/arialbd.ttf; font-encoding none; text-encoding none; pointsize 24
2014-04-10T09:37:04-04:00 0:00.020 0.010u 6.7.8 Annotate convert[16619]: annotate.c/GetTypeMetrics/798/Annotate
  Metrics: text: ⌘; width: 12.75; height: 28; ascent: 22; descent: -5; max advance: 48; bounds: 1.25,0  13.5781,18; origin: 15,0; pixels per em: 24,24; underline position: -5.0625; underline thickness: 3.35938
2014-04-10T09:37:04-04:00 0:00.020 0.010u 6.7.8 Annotate convert[16619]: annotate.c/RenderFreetype/1220/Annotate
  Font /usr/share/fonts/msttcorefonts/arialbd.ttf; font-encoding none; text-encoding none; pointsize 48
2014-04-10T09:37:04-04:00 0:00.020 0.010u 6.7.8 Annotate convert[16619]: annotate.c/GetTypeMetrics/798/Annotate
  Metrics: text: ⌘; width: 25.5156; height: 55; ascent: 43; descent: -10; max advance: 96; bounds: 2.48438,0  27.1406,35.5; origin: 29,0; pixels per em: 48,48; underline position: -5.0625; underline thickness: 3.35938
2014-04-10T09:37:04-04:00 0:00.020 0.010u 6.7.8 Annotate convert[16619]: annotate.c/RenderFreetype/1220/Annotate
  Font /usr/share/fonts/msttcorefonts/arialbd.ttf; font-encoding none; text-encoding none; pointsize 96
2014-04-10T09:37:04-04:00 0:00.020 0.020u 6.7.8 Annotate convert[16619]: annotate.c/GetTypeMetrics/798/Annotate
  Metrics: text: ⌘; width: 53.0312; height: 110; ascent: 87; descent: -20; max advance: 192; bounds: 4.96875,0  54.2812,70; origin: 59,0; pixels per em: 96,96; underline position: -5.0625; underline thickness: 3.35938
2014-04-10T09:37:04-04:00 0:00.020 0.020u 6.7.8 Annotate convert[16619]: annotate.c/RenderFreetype/1220/Annotate
  Font /usr/share/fonts/msttcorefonts/arialbd.ttf; font-encoding none; text-encoding none; pointsize 96
2014-04-10T09:37:04-04:00 0:00.020 0.020u 6.7.8 Annotate convert[16619]: annotate.c/GetTypeMetrics/798/Annotate
  Metrics: text: ⌘; width: 53.0312; height: 110; ascent: 87; descent: -20; max advance: 192; bounds: 4.96875,0  54.2812,70; origin: 59,0; pixels per em: 96,96; underline position: -5.0625; underline thickness: 3.35938
2014-04-10T09:37:04-04:00 0:00.020 0.020u 6.7.8 Annotate convert[16619]: annotate.c/RenderFreetype/1220/Annotate
  Font /usr/share/fonts/msttcorefonts/arialbd.ttf; font-encoding none; text-encoding none; pointsize 95
2014-04-10T09:37:04-04:00 0:00.020 0.020u 6.7.8 Annotate convert[16619]: annotate.c/GetTypeMetrics/798/Annotate
  Metrics: text: ⌘; width: 52.0781; height: 109; ascent: 86; descent: -20; max advance: 190; bounds: 4.92188,0  53.7188,70; origin: 58,0; pixels per em: 95,95; underline position: -5.0625; underline thickness: 3.35938
2014-04-10T09:37:04-04:00 0:00.020 0.020u 6.7.8 Annotate convert[16619]: annotate.c/RenderFreetype/1220/Annotate
  Font /usr/share/fonts/msttcorefonts/arialbd.ttf; font-encoding none; text-encoding none; pointsize 94
2014-04-10T09:37:04-04:00 0:00.020 0.020u 6.7.8 Annotate convert[16619]: annotate.c/GetTypeMetrics/798/Annotate
  Metrics: text: ⌘; width: 51.1406; height: 108; ascent: 85; descent: -20; max advance: 188; bounds: 4.85938,0  53.1562,68; origin: 57,0; pixels per em: 94,94; underline position: -5.0625; underline thickness: 3.35938
2014-04-10T09:37:04-04:00 0:00.020 0.020u 6.7.8 Annotate convert[16619]: annotate.c/RenderFreetype/1220/Annotate
  Font /usr/share/fonts/msttcorefonts/arialbd.ttf; font-encoding none; text-encoding none; pointsize 93
2014-04-10T09:37:04-04:00 0:00.020 0.020u 6.7.8 Annotate convert[16619]: annotate.c/GetTypeMetrics/798/Annotate
  Metrics: text: ⌘; width: 51.1875; height: 107; ascent: 84; descent: -20; max advance: 186; bounds: 4.8125,0  52.5781,67; origin: 57,0; pixels per em: 93,93; underline position: -5.0625; underline thickness: 3.35938
2014-04-10T09:37:04-04:00 0:00.020 0.020u 6.7.8 Annotate convert[16619]: annotate.c/RenderFreetype/1220/Annotate
  Font /usr/share/fonts/msttcorefonts/arialbd.ttf; font-encoding none; text-encoding none; pointsize 92
2014-04-10T09:37:04-04:00 0:00.020 0.020u 6.7.8 Annotate convert[16619]: annotate.c/GetTypeMetrics/798/Annotate
  Metrics: text: ⌘; width: 50.2344; height: 106; ascent: 83; descent: -19; max advance: 184; bounds: 4.76562,0  52.0156,67; origin: 56,0; pixels per em: 92,92; underline position: -5.0625; underline thickness: 3.35938
2014-04-10T09:37:04-04:00 0:00.020 0.020u 6.7.8 Annotate convert[16619]: annotate.c/RenderFreetype/1220/Annotate
  Font /usr/share/fonts/msttcorefonts/arialbd.ttf; font-encoding none; text-encoding none; pointsize 91
2014-04-10T09:37:04-04:00 0:00.030 0.020u 6.7.8 Annotate convert[16619]: annotate.c/GetTypeMetrics/798/Annotate
  Metrics: text: ⌘; width: 50.2969; height: 105; ascent: 82; descent: -19; max advance: 182; bounds: 4.70312,0  51.4531,65.4688; origin: 56,0; pixels per em: 91,91; underline position: -5.0625; underline thickness: 3.35938
2014-04-10T09:37:04-04:00 0:00.030 0.020u 6.7.8 Annotate convert[16619]: annotate.c/RenderFreetype/1220/Annotate
  Font /usr/share/fonts/msttcorefonts/arialbd.ttf; font-encoding none; text-encoding none; pointsize 90
2014-04-10T09:37:04-04:00 0:00.030 0.020u 6.7.8 Annotate convert[16619]: annotate.c/GetTypeMetrics/798/Annotate
  Metrics: text: ⌘; width: 49.3438; height: 103; ascent: 81; descent: -19; max advance: 180; bounds: 4.65625,0  50.8906,65.4688; origin: 55,0; pixels per em: 90,90; underline position: -5.0625; underline thickness: 3.35938
2014-04-10T09:37:04-04:00 0:00.030 0.020u 6.7.8 Annotate convert[16619]: annotate.c/RenderFreetype/1220/Annotate
  Font /usr/share/fonts/msttcorefonts/arialbd.ttf; font-encoding none; text-encoding none; pointsize 89
2014-04-10T09:37:04-04:00 0:00.030 0.020u 6.7.8 Annotate convert[16619]: annotate.c/GetTypeMetrics/798/Annotate
  Metrics: text: ⌘; width: 48.3906; height: 102; ascent: 81; descent: -19; max advance: 178; bounds: 4.60938,0  50.3281,64; origin: 54,0; pixels per em: 89,89; underline position: -5.0625; underline thickness: 3.35938
2014-04-10T09:37:04-04:00 0:00.030 0.020u 6.7.8 Annotate convert[16619]: annotate.c/RenderFreetype/1220/Annotate
  Font /usr/share/fonts/msttcorefonts/arialbd.ttf; font-encoding none; text-encoding none; pointsize 88
2014-04-10T09:37:04-04:00 0:00.030 0.020u 6.7.8 Annotate convert[16619]: annotate.c/GetTypeMetrics/798/Annotate
  Metrics: text: ⌘; width: 48.4375; height: 101; ascent: 80; descent: -19; max advance: 176; bounds: 4.5625,0  49.7656,64; origin: 54,0; pixels per em: 88,88; underline position: -5.0625; underline thickness: 3.35938
2014-04-10T09:37:04-04:00 0:00.030 0.020u 6.7.8 Annotate convert[16619]: annotate.c/RenderFreetype/1220/Annotate
  Font /usr/share/fonts/msttcorefonts/arialbd.ttf; font-encoding none; text-encoding none; pointsize 87
2014-04-10T09:37:04-04:00 0:00.030 0.020u 6.7.8 Annotate convert[16619]: annotate.c/GetTypeMetrics/798/Annotate
  Metrics: text: ⌘; width: 47.5; height: 100; ascent: 79; descent: -18; max advance: 174; bounds: 4.5,0  49.1875,63; origin: 53,0; pixels per em: 87,87; underline position: -5.0625; underline thickness: 3.35938
2014-04-10T09:37:04-04:00 0:00.030 0.020u 6.7.8 Annotate convert[16619]: annotate.c/RenderFreetype/1220/Annotate
  Font /usr/share/fonts/msttcorefonts/arialbd.ttf; font-encoding none; text-encoding none; pointsize 86
2014-04-10T09:37:04-04:00 0:00.030 0.020u 6.7.8 Annotate convert[16619]: annotate.c/GetTypeMetrics/798/Annotate
  Metrics: text: ⌘; width: 47.5469; height: 99; ascent: 78; descent: -18; max advance: 172; bounds: 4.45312,0  48.625,63; origin: 53,0; pixels per em: 86,86; underline position: -5.0625; underline thickness: 3.35938
2014-04-10T09:37:04-04:00 0:00.030 0.020u 6.7.8 Annotate convert[16619]: annotate.c/RenderFreetype/1220/Annotate
  Font /usr/share/fonts/msttcorefonts/arialbd.ttf; font-encoding none; text-encoding none; pointsize 86
2014-04-10T09:37:04-04:00 0:00.030 0.020u 6.7.8 Annotate convert[16619]: annotate.c/GetTypeMetrics/798/Annotate
  Metrics: text: ⌘; width: 47.5469; height: 99; ascent: 78; descent: -18; max advance: 172; bounds: 4.45312,0  48.625,63; origin: 53,0; pixels per em: 86,86; underline position: -5.0625; underline thickness: 3.35938
2014-04-10T09:37:04-04:00 0:00.030 0.020u 6.7.8 Annotate convert[16619]: annotate.c/RenderFreetype/1220/Annotate
  Font /usr/share/fonts/msttcorefonts/arialbd.ttf; font-encoding none; text-encoding none; pointsize 86

更新 #1 - 进一步调试

这个问题让我很烦恼,所以我想我终于弄清楚了。问题是字体的选择,并且它无法显示该特定字形。

  1. 首先,您可以使用此命令查看 中有哪些字体可用convert。让我们从这里开始。

    $ convert -list font | head -8
    
    Path: /etc/ImageMagick/type-ghostscript.xml
      Font: AvantGarde-Book
        family: AvantGarde
        style: Normal
        stretch: Normal
        weight: 400
        glyphs: /usr/share/fonts/default/Type1/a010013l.pfb
        ...
    

    上面是一个示例,每种字体都有与上面类似的线条。顺便说一句,运行此命令显示我们有数百种字体:

    $ convert -list font | grep Font | wc -l
    262
    
  2. 接下来,我们将\u2318使用我们拥有的每种字体来完成对字符进行编码的任务。这听起来很复杂,但对于通过 Bash 进行的一些深思熟虑的衬垫来说,这是相当微不足道的。

    $ for i in $(convert -list font | grep Font | awk '{print $2}'); \
        do convert -font $i -pointsize 36 label:⌘  ${i}.gif;done
    

    此代码片段将使用 for 循环来运行每种字体,运行命令的修改版本convert

  3. 现在我们来看看结果。许多字体无法显示此特定字形,但有几种可以,这似乎表明这不一定是 ImageMagick 中的错误,而是字体本身的限制。这是我拥有的可以显示此字形的字体列表。

    • DejaVu-Sans-Bold
    • DejaVu-Sans-Bold-Oblique
    • DejaVu-Sans-Book
    • DejaVu-Sans-Condensed-Bold
    • DejaVu-Sans-Condensed-Bold-Olique
    • DejaVu-Sans-Condensed
    • DejaVu-Sans-Condensed-Oblique
    • DejaVu-Sans-Mono-Bold
    • DejaVu-Sans-Mono-Bold-Oblique
    • DejaVu-Sans-Mono-Book
    • DejaVu-Sans-Mono-Oblique
    • DejaVu-Sans-Oblique
    • DejaVu-衬线-粗体
    • DejaVu-衬线-粗体-斜体
    • DejaVu 衬线书
    • DejaVu-Serif-Condensed-Bold
    • DejaVu-Serif-Condensed-Bold-Italic
    • DejaVu-Serif-Condensed
    • DejaVu-Serif-Condensed-Italic
    • DejaVu-衬线-斜体
    • 免费单色-常规
    • FreeSerif-Regular
    • STIX-数学-常规
    • STIX-常规
    • VL-哥特式-常规

    我直观地浏览了整个约 260 个结果.gif文件,以确定哪些有效,哪些无效。下面是一些有效的示例,以便您可以看到它们。

                                                SS1    SS2    SS3    SS4    SS5

参考

答案2

简短回答:潘戈

使用pango:⌘而不是label:⌘. Pango 使用 fontconfig 为每个字形找到合适的字体。

convert -pointsize 128 pango:⌘ command.png

转换-pointsize 128 pango:⌘ command.png

解释

潘戈是 ImageMagick 可以使用的渲染文本的库。与 ImageMagicklabel和相比,它有优点和缺点-draw text。如果所选字体中不存在字形,它将回退到其他字体。 Pango用途字体配置选择合适的字体。

$'\uXXXX'请注意,您可以使用Bash 和其他现代 shell 中可用的语法指定十六进制 Unicode 数字,而不是粘贴所需的字形:

convert -pointsize 128 pango:$'\u2318' command.png

字体配置

字体配置可以通过指定单个 Unicode 字符代码作为字符集来列出哪些字体可以呈现特定字形:

$ fc-list :charset=2318


/usr/share/fonts/truetype/dejavu/DejaVuSerif-Bold.ttf: DejaVu Serif:style=Bold
/home/b9/.local/share/fonts/DaxlinePro-Light.otf: DaxlinePro,DaxlinePro\-Light:style=Light,Regular
/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf: DejaVu Sans Mono:style=Book
/usr/share/fonts/truetype/dejavu/DejaVuSansCondensed-Oblique.ttf: DejaVu Sans,DejaVu Sans Condensed:style=Condensed Oblique,Oblique
/usr/share/fonts/truetype/dejavu/DejaVuSerifCondensed-BoldItalic.ttf: DejaVu Serif,DejaVu Serif Condensed:style=Condensed Bold Italic,Bold Italic
/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf: DejaVu Sans:style=Book
/home/b9/.local/share/fonts/DaxlinePro-ExtraBold.otf: DaxlinePro,DaxlinePro\-ExtraBold:style=ExtraBold,Regular
/home/b9/.local/share/fonts/DaxlinePro-Bold.otf: DaxlinePro,DaxlinePro\-Bold:style=Bold,Regular
/usr/share/fonts/truetype/dejavu/DejaVuSerifCondensed.ttf: DejaVu Serif,DejaVu Serif Condensed:style=Condensed,Book
/usr/share/fonts/truetype/dejavu/DejaVuSerifCondensed-Italic.ttf: DejaVu Serif,DejaVu Serif Condensed:style=Condensed Italic,Italic
/home/b9/.local/share/fonts/DaxlinePro-Black.otf: DaxlinePro,DaxlinePro\-Black:style=Black,Regular
/usr/share/fonts/truetype/dejavu/DejaVuSerif-BoldItalic.ttf: DejaVu Serif:style=Bold Italic
/usr/share/fonts/truetype/dejavu/DejaVuSansMono-Oblique.ttf: DejaVu Sans Mono:style=Oblique
/usr/share/fonts/truetype/dejavu/DejaVuSerifCondensed-Bold.ttf: DejaVu Serif,DejaVu Serif Condensed:style=Condensed Bold,Bold
/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf: DejaVu Sans:style=Bold
/usr/share/fonts/truetype/dejavu/DejaVuSansMono-BoldOblique.ttf: DejaVu Sans Mono:style=Bold Oblique
/usr/share/fonts/truetype/ancient-scripts/Symbola_hint.ttf: Symbola:style=Regular
/usr/share/fonts/truetype/dejavu/DejaVuSansCondensed-BoldOblique.ttf: DejaVu Sans,DejaVu Sans Condensed:style=Condensed Bold Oblique,Bold Oblique
/usr/share/fonts/truetype/dejavu/DejaVuSansCondensed.ttf: DejaVu Sans,DejaVu Sans Condensed:style=Condensed,Book
/usr/share/fonts/truetype/freefont/FreeSerif.ttf: FreeSerif:style=Regular,нормален,normal,obyčejné,Mittel,µεσαία,Normaali,Normál,Normale,Gemiddeld,odmiana zwykła,Обычный,Normálne,ปกติ,menengah,прямій,Navadno,vidējs,normalusis,عادی,vừa,Arrunta,सामान्य
/usr/share/fonts/opentype/freefont/FreeMono.otf: FreeMono:style=Regular,нормален,normal,obyčejné,Standard,µεσαία,Normaali,Normál,Normale,Standaard,Normalny,Обычный,Normálne,menengah,прямій,navadno,vidējs,normalusis,thường,Arrunta,सामान्य
/usr/share/fonts/truetype/dejavu/DejaVuSansCondensed-Bold.ttf: DejaVu Sans,DejaVu Sans Condensed:style=Condensed Bold,Bold
/usr/share/fonts/truetype/dejavu/DejaVuSansMono-Bold.ttf: DejaVu Sans Mono:style=Bold
/usr/share/fonts/truetype/dejavu/DejaVuSans-Oblique.ttf: DejaVu Sans:style=Oblique
/home/b9/.local/share/fonts/DaxlinePro-Regular.otf: DaxlinePro,DaxlinePro\-Regular:style=Regular
/home/b9/.local/share/fonts/DaxlinePro-Thin.otf: DaxlinePro,DaxlinePro\-Thin:style=Thin,Regular
/usr/share/fonts/truetype/dejavu/DejaVuSerif-Italic.ttf: DejaVu Serif:style=Italic
/usr/share/fonts/opentype/freefont/FreeSerif.otf: FreeSerif:style=Regular,нормален,normal,obyčejné,Mittel,µεσαία,Normaali,Normál,Normale,Gemiddeld,odmiana zwykła,Обычный,Normálne,ปกติ,menengah,прямій,Navadno,vidējs,normalusis,عادی,vừa,Arrunta,सामान्य
/home/b9/.local/share/fonts/DaxlinePro-Medium.otf: DaxlinePro,DaxlinePro\-Medium:style=Medium,Regular
/usr/share/fonts/truetype/unifont/unifont.ttf: Unifont:style=Regular
/usr/share/fonts/truetype/freefont/FreeMono.ttf: FreeMono:style=Regular,нормален,normal,obyčejné,Standard,µεσαία,Normaali,Normál,Normale,Standaard,Normalny,Обычный,Normálne,menengah,прямій,navadno,vidējs,normalusis,thường,Arrunta,सामान्य
/usr/share/fonts/truetype/dejavu/DejaVuSerif.ttf: DejaVu Serif:style=Book
/home/b9/.local/share/fonts/boecklinsuniverse/BoecklinsUniverse.ttf: Boecklins Universe:style=Regular
/usr/share/fonts/truetype/dejavu/DejaVuSans-BoldOblique.ttf: DejaVu Sans:style=Bold Oblique

人们可以利用该信息通过 ImageMagick 尝试各种字体,看看它们的外观如何。例如,

convert -font Unifont -pointsize 128 pango:⌘ command.png

使用 -font 指定 ImageMagick 应使用哪种字体

乌格列普(名称可能会更改)

为了方便起见,您可能希望使用我编写的脚本ugrep (名称可能会更改)使用以下命令列出了哪些已安装的字体包含特定字符-l

$ ugrep -l command key 
   ⌘    U+2318  PLACE OF INTEREST SIGN (command key)
                FreeMono 
                Unifont 
                Symbola 
                FreeSerif 
                DaxlinePro 
                Boecklins Universe 

如果您的终端支持 Sixel 图形,Ugrep 还可以显示每种字体中字符的渲染,方法是使用-Ln:

ugrep -L2 command key

xterm 运行 ugrep 的屏幕截图

相关内容