我正在为需要ImageMagick的Rails应用程序构建一些功能。我目前正在使用RMagick gem在图像上叠加自定义文本。我希望能够为用户提供一系列可供选择的字体,但是我发现GhostScript附带的字体库存(我的系统上有的字体)是相当有限的。
我想知道的是如何导入/加载自定义字体(例如Lato)以与ImageMagick一起使用,其方式可以在本地使用,也可以在Heroku上使用。具体来说,我正在构建一个图像标题(请参阅下面的代码),并希望能够指定一个不在列表中的字体。
这是我的示例代码:
font = 'Lato'
text = Magick::Image.read("caption:#{caption_text.to_s}") {
self.size = "#800x600"
self.colorspace = RGBColorspace
self.background_color = "Transparent"
self.depth = 8
self.format = 'PNG'
self.fill = '#333333'
self.font = font
}.first
如果我运行identify -list font
,我会得到以下ImageMagick可以在我的系统上访问的字体列表。
➜ Desktop identify -list font
Path: /usr/local/Cellar/imagemagick/6.9.3-0_2/etc/ImageMagick-6/type-ghostscript.xml
Font: AvantGarde-Book
family: AvantGarde
style: Normal
stretch: Normal
weight: 400
glyphs: /usr/local/share/ghostscript/fonts/a010013l.pfb
Font: AvantGarde-BookOblique
family: AvantGarde
style: Oblique
stretch: Normal
weight: 400
glyphs: /usr/local/share/ghostscript/fonts/a010033l.pfb
Font: AvantGarde-Demi
family: AvantGarde
style: Normal
stretch: Normal
weight: 600
glyphs: /usr/local/share/ghostscript/fonts/a010015l.pfb
Font: AvantGarde-DemiOblique
family: AvantGarde
style: Oblique
stretch: Normal
weight: 600
glyphs: /usr/local/share/ghostscript/fonts/a010035l.pfb
Font: Bookman-Demi
family: Bookman
style: Normal
stretch: Normal
weight: 600
glyphs: /usr/local/share/ghostscript/fonts/b018015l.pfb
Font: Bookman-DemiItalic
family: Bookman
style: Italic
stretch: Normal
weight: 600
glyphs: /usr/local/share/ghostscript/fonts/b018035l.pfb
Font: Bookman-Light
family: Bookman
style: Normal
stretch: Normal
weight: 300
glyphs: /usr/local/share/ghostscript/fonts/b018012l.pfb
Font: Bookman-LightItalic
family: Bookman
style: Italic
stretch: Normal
weight: 300
glyphs: /usr/local/share/ghostscript/fonts/b018032l.pfb
Font: Courier
family: Courier
style: Normal
stretch: Normal
weight: 400
glyphs: /usr/local/share/ghostscript/fonts/n022003l.pfb
Font: Courier-Bold
family: Courier
style: Normal
stretch: Normal
weight: 700
glyphs: /usr/local/share/ghostscript/fonts/n022004l.pfb
Font: Courier-BoldOblique
family: Courier
style: Oblique
stretch: Normal
weight: 700
glyphs: /usr/local/share/ghostscript/fonts/n022024l.pfb
Font: Courier-Oblique
family: Courier
style: Oblique
stretch: Normal
weight: 400
glyphs: /usr/local/share/ghostscript/fonts/n022023l.pfb
Font: fixed
family: Helvetica
style: Normal
stretch: Normal
weight: 400
glyphs: /usr/local/share/ghostscript/fonts/n019003l.pfb
Font: Helvetica
family: Helvetica
style: Normal
stretch: Normal
weight: 400
glyphs: /usr/local/share/ghostscript/fonts/n019003l.pfb
Font: Helvetica-Bold
family: Helvetica
style: Normal
stretch: Normal
weight: 700
glyphs: /usr/local/share/ghostscript/fonts/n019004l.pfb
Font: Helvetica-BoldOblique
family: Helvetica
style: Italic
stretch: Normal
weight: 700
glyphs: /usr/local/share/ghostscript/fonts/n019024l.pfb
Font: Helvetica-Narrow
family: Helvetica Narrow
style: Normal
stretch: Condensed
weight: 400
glyphs: /usr/local/share/ghostscript/fonts/n019043l.pfb
Font: Helvetica-Narrow-Bold
family: Helvetica Narrow
style: Normal
stretch: Condensed
weight: 700
glyphs: /usr/local/share/ghostscript/fonts/n019044l.pfb
Font: Helvetica-Narrow-BoldOblique
family: Helvetica Narrow
style: Oblique
stretch: Condensed
weight: 700
glyphs: /usr/local/share/ghostscript/fonts/n019064l.pfb
Font: Helvetica-Narrow-Oblique
family: Helvetica Narrow
style: Oblique
stretch: Condensed
weight: 400
glyphs: /usr/local/share/ghostscript/fonts/n019063l.pfb
Font: Helvetica-Oblique
family: Helvetica
style: Italic
stretch: Normal
weight: 400
glyphs: /usr/local/share/ghostscript/fonts/n019023l.pfb
Font: NewCenturySchlbk-Bold
family: NewCenturySchlbk
style: Normal
stretch: Normal
weight: 700
glyphs: /usr/local/share/ghostscript/fonts/c059016l.pfb
Font: NewCenturySchlbk-BoldItalic
family: NewCenturySchlbk
style: Italic
stretch: Normal
weight: 700
glyphs: /usr/local/share/ghostscript/fonts/c059036l.pfb
Font: NewCenturySchlbk-Italic
family: NewCenturySchlbk
style: Italic
stretch: Normal
weight: 400
glyphs: /usr/local/share/ghostscript/fonts/c059033l.pfb
Font: NewCenturySchlbk-Roman
family: NewCenturySchlbk
style: Normal
stretch: Normal
weight: 400
glyphs: /usr/local/share/ghostscript/fonts/c059013l.pfb
Font: Palatino-Bold
family: Palatino
style: Normal
stretch: Normal
weight: 700
glyphs: /usr/local/share/ghostscript/fonts/p052004l.pfb
Font: Palatino-BoldItalic
family: Palatino
style: Italic
stretch: Normal
weight: 700
glyphs: /usr/local/share/ghostscript/fonts/p052024l.pfb
Font: Palatino-Italic
family: Palatino
style: Italic
stretch: Normal
weight: 400
glyphs: /usr/local/share/ghostscript/fonts/p052023l.pfb
Font: Palatino-Roman
family: Palatino
style: Normal
stretch: Normal
weight: 400
glyphs: /usr/local/share/ghostscript/fonts/p052003l.pfb
Font: Symbol
family: Symbol
style: Normal
stretch: Normal
weight: 400
glyphs: /usr/local/share/ghostscript/fonts/s050000l.pfb
Font: Times-Bold
family: Times
style: Normal
stretch: Normal
weight: 700
glyphs: /usr/local/share/ghostscript/fonts/n021004l.pfb
Font: Times-BoldItalic
family: Times
style: Italic
stretch: Normal
weight: 700
glyphs: /usr/local/share/ghostscript/fonts/n021024l.pfb
Font: Times-Italic
family: Times
style: Italic
stretch: Normal
weight: 400
glyphs: /usr/local/share/ghostscript/fonts/n021023l.pfb
Font: Times-Roman
family: Times
style: Normal
stretch: Normal
weight: 400
glyphs: /usr/local/share/ghostscript/fonts/n021003l.pfb
如果我在Heroku上运行bash,我会得到以下列表:
➜ Desktop heroku run bash
Running bash on staging-myapp... up, run.5220
~ $ identify -list font
Path: /etc/ImageMagick/type-ghostscript.xml
Font: AvantGarde-Book
family: AvantGarde
style: Normal
stretch: Normal
weight: 400
glyphs: /usr/share/fonts/type1/gsfonts/a010013l.pfb
Font: AvantGarde-BookOblique
family: AvantGarde
style: Oblique
stretch: Normal
weight: 400
glyphs: /usr/share/fonts/type1/gsfonts/a010033l.pfb
Font: AvantGarde-Demi
family: AvantGarde
style: Normal
stretch: Normal
weight: 600
glyphs: /usr/share/fonts/type1/gsfonts/a010015l.pfb
Font: AvantGarde-DemiOblique
family: AvantGarde
style: Oblique
stretch: Normal
weight: 600
glyphs: /usr/share/fonts/type1/gsfonts/a010035l.pfb
Font: Bookman-Demi
family: Bookman
style: Normal
stretch: Normal
weight: 600
glyphs: /usr/share/fonts/type1/gsfonts/b018015l.pfb
Font: Bookman-DemiItalic
family: Bookman
style: Italic
stretch: Normal
weight: 600
glyphs: /usr/share/fonts/type1/gsfonts/b018035l.pfb
Font: Bookman-Light
family: Bookman
style: Normal
stretch: Normal
weight: 300
glyphs: /usr/share/fonts/type1/gsfonts/b018012l.pfb
Font: Bookman-LightItalic
family: Bookman
style: Italic
stretch: Normal
weight: 300
glyphs: /usr/share/fonts/type1/gsfonts/b018032l.pfb
Font: Courier
family: Courier
style: Normal
stretch: Normal
weight: 400
glyphs: /usr/share/fonts/type1/gsfonts/n022003l.pfb
Font: Courier-Bold
family: Courier
style: Normal
stretch: Normal
weight: 700
glyphs: /usr/share/fonts/type1/gsfonts/n022004l.pfb
Font: Courier-BoldOblique
family: Courier
style: Oblique
stretch: Normal
weight: 700
glyphs: /usr/share/fonts/type1/gsfonts/n022024l.pfb
Font: Courier-Oblique
family: Courier
style: Oblique
stretch: Normal
weight: 400
glyphs: /usr/share/fonts/type1/gsfonts/n022023l.pfb
Font: fixed
family: Helvetica
style: Normal
stretch: Normal
weight: 400
glyphs: /usr/share/fonts/type1/gsfonts/n019003l.pfb
Font: Helvetica
family: Helvetica
style: Normal
stretch: Normal
weight: 400
glyphs: /usr/share/fonts/type1/gsfonts/n019003l.pfb
Font: Helvetica-Bold
family: Helvetica
style: Normal
stretch: Normal
weight: 700
glyphs: /usr/share/fonts/type1/gsfonts/n019004l.pfb
Font: Helvetica-BoldOblique
family: Helvetica
style: Italic
stretch: Normal
weight: 700
glyphs: /usr/share/fonts/type1/gsfonts/n019024l.pfb
Font: Helvetica-Narrow
family: Helvetica Narrow
style: Normal
stretch: Condensed
weight: 400
glyphs: /usr/share/fonts/type1/gsfonts/n019043l.pfb
Font: Helvetica-Narrow-Bold
family: Helvetica Narrow
style: Normal
stretch: Condensed
weight: 700
glyphs: /usr/share/fonts/type1/gsfonts/n019044l.pfb
Font: Helvetica-Narrow-BoldOblique
family: Helvetica Narrow
style: Oblique
stretch: Condensed
weight: 700
glyphs: /usr/share/fonts/type1/gsfonts/n019064l.pfb
Font: Helvetica-Narrow-Oblique
family: Helvetica Narrow
style: Oblique
stretch: Condensed
weight: 400
glyphs: /usr/share/fonts/type1/gsfonts/n019063l.pfb
Font: Helvetica-Oblique
family: Helvetica
style: Italic
stretch: Normal
weight: 400
glyphs: /usr/share/fonts/type1/gsfonts/n019023l.pfb
Font: NewCenturySchlbk-Bold
family: NewCenturySchlbk
style: Normal
stretch: Normal
weight: 700
glyphs: /usr/share/fonts/type1/gsfonts/c059016l.pfb
Font: NewCenturySchlbk-BoldItalic
family: NewCenturySchlbk
style: Italic
stretch: Normal
weight: 700
glyphs: /usr/share/fonts/type1/gsfonts/c059036l.pfb
Font: NewCenturySchlbk-Italic
family: NewCenturySchlbk
style: Italic
stretch: Normal
weight: 400
glyphs: /usr/share/fonts/type1/gsfonts/c059033l.pfb
Font: NewCenturySchlbk-Roman
family: NewCenturySchlbk
style: Normal
stretch: Normal
weight: 400
glyphs: /usr/share/fonts/type1/gsfonts/c059013l.pfb
Font: Palatino-Bold
family: Palatino
style: Normal
stretch: Normal
weight: 700
glyphs: /usr/share/fonts/type1/gsfonts/p052004l.pfb
Font: Palatino-BoldItalic
family: Palatino
style: Italic
stretch: Normal
weight: 700
glyphs: /usr/share/fonts/type1/gsfonts/p052024l.pfb
Font: Palatino-Italic
family: Palatino
style: Italic
stretch: Normal
weight: 400
glyphs: /usr/share/fonts/type1/gsfonts/p052023l.pfb
Font: Palatino-Roman
family: Palatino
style: Normal
stretch: Normal
weight: 400
glyphs: /usr/share/fonts/type1/gsfonts/p052003l.pfb
Font: Symbol
family: Symbol
style: Normal
stretch: Normal
weight: 400
glyphs: /usr/share/fonts/type1/gsfonts/s050000l.pfb
Font: Times-Bold
family: Times
style: Normal
stretch: Normal
weight: 700
glyphs: /usr/share/fonts/type1/gsfonts/n021004l.pfb
Font: Times-BoldItalic
family: Times
style: Italic
stretch: Normal
weight: 700
glyphs: /usr/share/fonts/type1/gsfonts/n021024l.pfb
Font: Times-Italic
family: Times
style: Italic
stretch: Normal
weight: 400
glyphs: /usr/share/fonts/type1/gsfonts/n021023l.pfb
Font: Times-Roman
family: Times
style: Normal
stretch: Normal
weight: 400
glyphs: /usr/share/fonts/type1/gsfonts/n021003l.pfb
Path: System Fonts
Font: Century-Schoolbook-Bold
family: Century Schoolbook
style: Normal
stretch: Normal
weight: 700
glyphs: /usr/share/fonts/type1/gsfonts/c059016l.pfb
Font: Century-Schoolbook-Bold-Italic
family: Century Schoolbook
style: Italic
stretch: Normal
weight: 700
glyphs: /usr/share/fonts/type1/gsfonts/c059036l.pfb
Font: Century-Schoolbook-Italic
family: Century Schoolbook
style: Italic
stretch: Normal
weight: 400
glyphs: /usr/share/fonts/type1/gsfonts/c059033l.pfb
Font: Century-Schoolbook-Roman
family: Century Schoolbook
style: Normal
stretch: Normal
weight: 500
glyphs: /usr/share/fonts/type1/gsfonts/c059013l.pfb
Font: DejaVu-Sans-Bold
family: DejaVu Sans
style: Normal
stretch: Normal
weight: 700
glyphs: /usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf
Font: DejaVu-Sans-Bold-Oblique
family: DejaVu Sans
style: Oblique
stretch: Normal
weight: 700
glyphs: /usr/share/fonts/truetype/dejavu/DejaVuSans-BoldOblique.ttf
Font: DejaVu-Sans-Book
family: DejaVu Sans
style: Normal
stretch: Normal
weight: 400
glyphs: /usr/share/fonts/truetype/dejavu/DejaVuSans.ttf
Font: DejaVu-Sans-Condensed
family: DejaVu Sans
style: Normal
stretch: SemiCondensed
weight: 400
glyphs: /usr/share/fonts/truetype/dejavu/DejaVuSansCondensed.ttf
Font: DejaVu-Sans-Condensed-Bold
family: DejaVu Sans
style: Normal
stretch: SemiCondensed
weight: 700
glyphs: /usr/share/fonts/truetype/dejavu/DejaVuSansCondensed-Bold.ttf
Font: DejaVu-Sans-Condensed-Bold-Oblique
family: DejaVu Sans
style: Oblique
stretch: SemiCondensed
weight: 700
glyphs: /usr/share/fonts/truetype/dejavu/DejaVuSansCondensed-BoldOblique.ttf
Font: DejaVu-Sans-Condensed-Oblique
family: DejaVu Sans
style: Oblique
stretch: SemiCondensed
weight: 400
glyphs: /usr/share/fonts/truetype/dejavu/DejaVuSansCondensed-Oblique.ttf
Font: DejaVu-Sans-ExtraLight
family: DejaVu Sans
style: Normal
stretch: Normal
weight: 200
glyphs: /usr/share/fonts/truetype/dejavu/DejaVuSans-ExtraLight.ttf
Font: DejaVu-Sans-Mono-Bold
family: DejaVu Sans Mono
style: Normal
stretch: Normal
weight: 700
glyphs: /usr/share/fonts/truetype/dejavu/DejaVuSansMono-Bold.ttf
Font: DejaVu-Sans-Mono-Bold-Oblique
family: DejaVu Sans Mono
style: Oblique
stretch: Normal
weight: 700
glyphs: /usr/share/fonts/truetype/dejavu/DejaVuSansMono-BoldOblique.ttf
Font: DejaVu-Sans-Mono-Book
family: DejaVu Sans Mono
style: Normal
stretch: Normal
weight: 400
glyphs: /usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf
Font: DejaVu-Sans-Mono-Oblique
family: DejaVu Sans Mono
style: Oblique
stretch: Normal
weight: 400
glyphs: /usr/share/fonts/truetype/dejavu/DejaVuSansMono-Oblique.ttf
Font: DejaVu-Sans-Oblique
family: DejaVu Sans
style: Oblique
stretch: Normal
weight: 400
glyphs: /usr/share/fonts/truetype/dejavu/DejaVuSans-Oblique.ttf
Font: DejaVu-Serif-Bold
family: DejaVu Serif
style: Normal
stretch: Normal
weight: 700
glyphs: /usr/share/fonts/truetype/dejavu/DejaVuSerif-Bold.ttf
Font: DejaVu-Serif-Bold-Italic
family: DejaVu Serif
style: Italic
stretch: Normal
weight: 700
glyphs: /usr/share/fonts/truetype/dejavu/DejaVuSerif-BoldItalic.ttf
Font: DejaVu-Serif-Book
family: DejaVu Serif
style: Normal
stretch: Normal
weight: 400
glyphs: /usr/share/fonts/truetype/dejavu/DejaVuSerif.ttf
Font: DejaVu-Serif-Condensed
family: DejaVu Serif
style: Normal
stretch: SemiCondensed
weight: 400
glyphs: /usr/share/fonts/truetype/dejavu/DejaVuSerifCondensed.ttf
Font: DejaVu-Serif-Condensed-Bold
family: DejaVu Serif
style: Normal
stretch: SemiCondensed
weight: 700
glyphs: /usr/share/fonts/truetype/dejavu/DejaVuSerifCondensed-Bold.ttf
Font: DejaVu-Serif-Condensed-Bold-Italic
family: DejaVu Serif
style: Italic
stretch: SemiCondensed
weight: 700
glyphs: /usr/share/fonts/truetype/dejavu/DejaVuSerifCondensed-BoldItalic.ttf
Font: DejaVu-Serif-Condensed-Italic
family: DejaVu Serif
style: Italic
stretch: SemiCondensed
weight: 400
glyphs: /usr/share/fonts/truetype/dejavu/DejaVuSerifCondensed-Italic.ttf
Font: DejaVu-Serif-Italic
family: DejaVu Serif
style: Italic
stretch: Normal
weight: 400
glyphs: /usr/share/fonts/truetype/dejavu/DejaVuSerif-Italic.ttf
Font: Dingbats-Regular
family: Dingbats
style: Normal
stretch: Normal
weight: 400
glyphs: /usr/share/fonts/type1/gsfonts/d050000l.pfb
Font: Nimbus-Mono-Bold
family: Nimbus Mono
style: Normal
stretch: Normal
weight: 700
glyphs: /usr/share/fonts/type1/gsfonts/n022004l.pfb
Font: Nimbus-Mono-Bold-Oblique
family: Nimbus Mono
style: Oblique
stretch: Normal
weight: 700
glyphs: /usr/share/fonts/type1/gsfonts/n022024l.pfb
Font: Nimbus-Mono-Regular
family: Nimbus Mono
style: Normal
stretch: Normal
weight: 400
glyphs: /usr/share/fonts/type1/gsfonts/n022003l.pfb
Font: Nimbus-Mono-Regular-Oblique
family: Nimbus Mono
style: Oblique
stretch: Normal
weight: 400
glyphs: /usr/share/fonts/type1/gsfonts/n022023l.pfb
Font: Nimbus-Roman-No9-Medium
family: Nimbus Roman No9
style: Normal
stretch: Normal
weight: 700
glyphs: /usr/share/fonts/type1/gsfonts/n021004l.pfb
Font: Nimbus-Roman-No9-Medium-Italic
family: Nimbus Roman No9
style: Italic
stretch: Normal
weight: 700
glyphs: /usr/share/fonts/type1/gsfonts/n021024l.pfb
Font: Nimbus-Roman-No9-Regular
family: Nimbus Roman No9
style: Normal
stretch: Normal
weight: 400
glyphs: /usr/share/fonts/type1/gsfonts/n021003l.pfb
Font: Nimbus-Roman-No9-Regular-Italic
family: Nimbus Roman No9
style: Italic
stretch: Normal
weight: 400
glyphs: /usr/share/fonts/type1/gsfonts/n021023l.pfb
Font: Nimbus-Sans-Bold
family: Nimbus Sans
style: Normal
stretch: Normal
weight: 700
glyphs: /usr/share/fonts/type1/gsfonts/n019004l.pfb
Font: Nimbus-Sans-Bold-Condensed
family: Nimbus Sans
style: Normal
stretch: Condensed
weight: 700
glyphs: /usr/share/fonts/type1/gsfonts/n019044l.pfb
Font: Nimbus-Sans-Bold-Condensed-Italic
family: Nimbus Sans
style: Italic
stretch: Condensed
weight: 700
glyphs: /usr/share/fonts/type1/gsfonts/n019064l.pfb
Font: Nimbus-Sans-Bold-Italic
family: Nimbus Sans
style: Italic
stretch: Normal
weight: 700
glyphs: /usr/share/fonts/type1/gsfonts/n019024l.pfb
Font: Nimbus-Sans-Regular
family: Nimbus Sans
style: Normal
stretch: Normal
weight: 400
glyphs: /usr/share/fonts/type1/gsfonts/n019003l.pfb
Font: Nimbus-Sans-Regular-Condensed
family: Nimbus Sans
style: Normal
stretch: Condensed
weight: 400
glyphs: /usr/share/fonts/type1/gsfonts/n019043l.pfb
Font: Nimbus-Sans-Regular-Condensed-Italic
family: Nimbus Sans
style: Italic
stretch: Condensed
weight: 400
glyphs: /usr/share/fonts/type1/gsfonts/n019063l.pfb
Font: Nimbus-Sans-Regular-Italic
family: Nimbus Sans
style: Italic
stretch: Normal
weight: 400
glyphs: /usr/share/fonts/type1/gsfonts/n019023l.pfb
Font: Standard-Symbols-Regular
family: Standard Symbols
style: Normal
stretch: Normal
weight: 400
glyphs: /usr/share/fonts/type1/gsfonts/s050000l.pfb
Font: URW-Bookman-Demi-Bold
family: URW Bookman
style: Normal
stretch: Normal
weight: 700
glyphs: /usr/share/fonts/type1/gsfonts/b018015l.pfb
Font: URW-Bookman-Demi-Bold-Italic
family: URW Bookman
style: Italic
stretch: Normal
weight: 700
glyphs: /usr/share/fonts/type1/gsfonts/b018035l.pfb
Font: URW-Bookman-Light
family: URW Bookman
style: Normal
stretch: Normal
weight: 400
glyphs: /usr/share/fonts/type1/gsfonts/b018012l.pfb
Font: URW-Bookman-Light-Italic
family: URW Bookman
style: Italic
stretch: Normal
weight: 400
glyphs: /usr/share/fonts/type1/gsfonts/b018032l.pfb
Font: URW-Chancery-Medium-Italic
family: URW Chancery
style: Italic
stretch: Normal
weight: 500
glyphs: /usr/share/fonts/type1/gsfonts/z003034l.pfb
Font: URW-Gothic-Book
family: URW Gothic
style: Normal
stretch: Normal
weight: 300
glyphs: /usr/share/fonts/type1/gsfonts/a010013l.pfb
Font: URW-Gothic-Book-Oblique
family: URW Gothic
style: Oblique
stretch: Normal
weight: 300
glyphs: /usr/share/fonts/type1/gsfonts/a010033l.pfb
Font: URW-Gothic-Demi
family: URW Gothic
style: Normal
stretch: Normal
weight: 600
glyphs: /usr/share/fonts/type1/gsfonts/a010015l.pfb
Font: URW-Gothic-Demi-Oblique
family: URW Gothic
style: Oblique
stretch: Normal
weight: 600
glyphs: /usr/share/fonts/type1/gsfonts/a010035l.pfb
Font: URW-Palladio-Bold
family: URW Palladio
style: Normal
stretch: Normal
weight: 700
glyphs: /usr/share/fonts/type1/gsfonts/p052004l.pfb
Font: URW-Palladio-Bold-Italic
family: URW Palladio
style: Italic
stretch: Normal
weight: 700
glyphs: /usr/share/fonts/type1/gsfonts/p052024l.pfb
Font: URW-Palladio-Italic
family: URW Palladio
style: Italic
stretch: Normal
weight: 400
glyphs: /usr/share/fonts/type1/gsfonts/p052023l.pfb
Font: URW-Palladio-Roman
family: URW Palladio
style: Normal
stretch: Normal
weight: 500
glyphs: /usr/share/fonts/type1/gsfonts/p052003l.pfb
显然,Heroku上的可用选项比我机器上的选项更广泛,但仍然非常有限。
答案 0 :(得分:2)
我明白了!这很容易做到,如果不是太明显,不能在文档中提到。如果有更好的方法,请分享,我会接受你的回答。
创建新caption
时(这可能也适用于其他类型的文字),您可以将字体指定为字符串(例如ArialBold
),如果它在/etc/ImageMagick/type-ghostscript.xml
中。如果它没有列在那里,你也可以将绝对文件路径作为字符串传递。确保使用双引号。 ImageMagick将接受TTF和OTF字体(可能是其他人,但我还没有测试过)。
因此,如果我运行以下代码,它将为字体选择Arial Bold Italic
,即使它不在我的fontmap中。
require 'RMagick'
include Magick
caption_text = "This is a test"
font = "/Library/Fonts/Arial\ Bold\ Italic.ttf"
text = Magick::Image.read("caption:#{caption_text}") {
# this wraps the text to fixed width
self.size = "800x600"
self.colorspace = RGBColorspace
self.background_color = "Transparent"
self.depth = 8
self.format = 'PNG'
self.fill = '#333333'
self.font = font
}.first
text.write('text.png')
这也应该是Heroku的安全,因为我可以轻松地在我的assets / fonts文件夹中包含自定义字体。