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/
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With