Ubuntu + RMagickでフォントが無くて画像の出力ができない
2021/04/16
問題
RMagick(正確にはgruff)でグラフ画像を出力しようとしたらフォントが無くてコケた
irb(main):012:0> g.write('exciting.png')
Traceback (most recent call last):
14: from /usr/local/bin/irb:23:in `<main>'
13: from /usr/local/bin/irb:23:in `load'
12: from /usr/local/lib/ruby/gems/2.7.0/gems/irb-1.2.6/exe/irb:11:in `<top (required)>'
11: from (irb):12
10: from /usr/local/bundle/gems/gruff-0.12.1/lib/gruff/base.rb:419:in `write'
9: from /usr/local/bundle/gems/gruff-0.12.1/lib/gruff/base.rb:437:in `to_image'
8: from /usr/local/bundle/gems/gruff-0.12.1/lib/gruff/line.rb:172:in `draw'
7: from /usr/local/bundle/gems/gruff-0.12.1/lib/gruff/base.rb:468:in `draw'
6: from /usr/local/bundle/gems/gruff-0.12.1/lib/gruff/base.rb:495:in `setup_drawing'
5: from /usr/local/bundle/gems/gruff-0.12.1/lib/gruff/base.rb:557:in `setup_graph_measurements'
4: from /usr/local/bundle/gems/gruff-0.12.1/lib/gruff/base.rb:792:in `setup_marker_caps_height'
3: from /usr/local/bundle/gems/gruff-0.12.1/lib/gruff/base.rb:917:in `calculate_caps_height'
2: from /usr/local/bundle/gems/gruff-0.12.1/lib/gruff/renderer/text.rb:54:in `metrics'
1: from /usr/local/bundle/gems/gruff-0.12.1/lib/gruff/renderer/text.rb:54:in `get_type_metrics'
Magick::ImageMagickError (unable to read font `helvetica' @ error/annotate.c/RenderFreetype/1338)
解決方法
ghostscriptを入れてあげればいいらしい
$ sudo apt update && sudo apt install -y ghostscript
参考
ImageMagick error when executing png gantt · Issue #65 · docker-library/redmine