ruby-on-rails - 在 Heroku 上的 ImageMagick 中使用自定义字体

标签 ruby-on-rails heroku fonts imagemagick rmagick

我正在将一些功能构建到需要 ImageMagick 的 Rails 应用程序中。我目前正在使用 RMagick gem 在图像上覆盖自定义文本。我希望能够为用户提供一系列可供选择的字体,但是我发现 GhostScript 附带的一组库存字体(我的系统上有这些字体)相当有限。

我想知道的是如何导入/加载自定义字体(例如 Lato)以在本地和 Heroku 上工作的方式与 ImageMagick 一起使用。具体来说,我正在构建一个图像标题(请参阅下面的代码)并希望能够指定不在列表中的字体。

这是我的示例代码:

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 上的可用选项比我机器上的更广泛,但仍然非常有限。

最佳答案

我想到了!做起来非常容易,如果不是太明显而无法在文档中提及的话。如果有更好的方法来做到这一点,请分享,我会接受你的答案。

创建新时caption (这可能也适用于其他类型的文本),如果它在您的 ArialBold 中,您可以将字体指定为字符串(例如 /etc/ImageMagick/type-ghostscript.xml ) .如果它没有在那里列出,您也可以将绝对文件路径作为字符串传递。确保使用双引号。 ImageMagick 将接受 TTF 和 OTF 字体(可能是其他字体,但我还没有测试过)。

因此,如果我运行以下代码,它将选择 Arial Bold Italic对于字体,即使它不在我的字体映射中。

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 /字体文件夹中包含自定义字体。

关于ruby-on-rails - 在 Heroku 上的 ImageMagick 中使用自定义字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36990657/

相关文章:

javascript - 使用 javascript 导入多个自定义字体有相同的方法吗?

css - firefox 上的 font-face 在使用 font-weight normal 时会导致问题

mysql - 使用大写 ID 从 Rails 应用程序保存 MYSQL 数据库中:Mysql2::Error: Field 'ID' 没有默认值

ruby-on-rails - 修改 rake db 命令以使用不同的 mysql 引擎

javascript - Rails AJax 获取动态 URL

ruby - IndexTank 自动完成 : modifying the autocomplete field text for each result returned

css - 基本 Casper 主题中的字体更改导致图标消失

ruby-on-rails - 如何使整个站点只能由单个管理员访问

java - 正在运行的 Heroku Java WAR 应用程序现在失败 : "Unable to access jarfile webapp-runner-7.0.40.0.jar"

ruby-on-rails - Rails 5,用 Postgres 数组替换连接表