rmagick / rmagick

Ruby bindings for ImageMagick
https://rmagick.github.io/
MIT License
696 stars 140 forks source link

ImageMagick: unable to read font 'Helvetica' #1380

Closed tbcooney closed 1 month ago

tbcooney commented 1 year ago

Description

ImageMagick suddenly began to raise an Magick::ImageMagickError stating that it is unable to read font 'Helvetica' @ error/annotate.c/RenderFreetype/1396 when running a unit test for a Ruby on Rails app through CI using GitHub Actions. This is raised when installing either gsfonts or ghostscript. The unit test previously passed and it was only in the last 4 days that the error started to be raised.

The ImageMagick package is looking for the font installation in the /usr/local so in the CI workflow we install the font paths to make Github Actions pass.

First to see what fonts are installed, I ran this command locally:

convert -list font

For Helvetica it shown under the usr/local path:

Font: fixed
    family: Helvetica
    style: Normal
    stretch: Normal
    weight: 400
    glyphs: /usr/local/share/ghostscript/fonts/n019003l.pfb

In Github Actions there will be no such path, so it seems that ghostscript fonts (or gsfonts) must be included.

- name: Install dependencies
  run: |
    sudo apt-get install -y -qq libvips ghostscript imagemagick
    yarn install --frozen-lockfile

Again, this unit test previously passed and it was only in the last 4 days that the error started to be raised.

Steps to Reproduce

We have a service that contains two actions for drawing something on an image. The class is being instantiated in the following way:

class AnnotateSignature
  attr_reader :text
  private :text

  def initialize(text)
    @text = text
  end

  def annotate(*args)
    draw.annotate(*args, text)
  end

  private

  def draw
    Magick::Draw.new.tap do |text|
      text.font = "Helvetica"
      text.pointsize = 38
      text.font_weight = Magick::BoldWeight
      text.fill = "black"
      text.gravity = Magick::SouthGravity
    end
  end
end

System Configuration

Watson1978 commented 1 month ago

Sounds this is related to runner image of github action. I think the creation of the image needs to be properly updated.

Feel free to reopen if you have any problem yet.