Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rmagick unable to read font

I have a piece of code that draws text on top of an image in my Rails app and since short while ago, probably having to to with upgrading to OS X Yosemite, it's having an issue with reading fonts on my local machine (production server is working fine).

I can reduce it to this example:

require 'rvg/rvg'
font = '"/Users/xxxxxxxx/xxxx/app/assets/fonts/PTSans-Regular.ttf"'
rvg = Magick::RVG.new(100,100) do |canvas|
  canvas.text(0, 0, 'my text').styles(font: font)  
end  
rvg.draw

I get this error

Magick::ImageMagickError: unable to read font `"/Users/xxxxxxxx/xxxx/app/assets/fonts/PTSans-Regular.ttf"' @ error/annotate.c/RenderFreetype/1153: `(null)'
from /Users/xxxxxxxx/.rvm/gems/ruby-2.0.0-p353@xxxxxxxx/gems/rmagick-2.13.2/lib/rvg/misc.rb:322:in `get_type_metrics'

I tried reinstalling imagemagick and the rmagick gem, also with these flags:

brew install imagemagick --disable-openmp --build-from-source

Also, if I change

font = "/Users/xxxxxx/xxxxx/app/assets/fonts/PTSans-Regular.ttf"

thinking that the extra quotes could get in the way, then I get

Magick::ImageMagickError: non-conforming drawing primitive definition `Users/xxxxx/xxxx/app/assets/fonts/PTSans-Regular.ttf' @ error/draw.c/DrawImage/3170
from /Users/xxxxxxx/.rvm/gems/ruby-2.0.0-p353@xxxx/gems/rmagick-2.13.2/lib/rvg/misc.rb:546:in `draw'

I have also tried to install the latest version of XQuartz from http://xquartz.macosforge.org/landing/

like image 589
Cristian Avatar asked Jan 20 '15 11:01

Cristian


1 Answers

Strangely enough, this fixed it:

brew install gs

The error got me confused because it didn't say anything about ghostscript, however, it worked according to https://stackoverflow.com/a/13936374/322253

like image 121
Cristian Avatar answered Nov 11 '22 00:11

Cristian