rmagick: Ruby 2.6.0+ Error when creating image from PDF on macOS

Hi Guys,

When trying to convert a PDF to an image we are getting the following crash:

file_blob = open("#{Rails.root}/spec/services/pdf/assets/3860-001_original.pdf", "rb").read

image1 = Magick::Image::from_blob(file_blob) do 
  self.format = 'PDF'
  self.density = 144
  self.quality = 100
  self.colorspace = Magick::RGBColorspace 
end
Magick::ImageMagickError: FailedToExecuteCommand `'gs' -sstdout=%stderr -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 '-sDEVICE=pngalpha' -dTextAlphaBits=4 -dGraphicsAlphaBits=4 '-r144x144'  '-sOutputFile=/var/folders/gp/74j6yggx6rjf_hdbg2v7fjsw0000gn/T/magick-81244zcSY9rmgFD4G%d' '-f/var/folders/gp/74j6yggx6rjf_hdbg2v7fjsw0000gn/T/magick-81244QWjhSzMnzzFn' '-f/var/folders/gp/74j6yggx6rjf_hdbg2v7fjsw0000gn/T/magick-81244YeH8uSjx5tZt'' (-1) @ error/delegate.c/ExternalD

Have tried the exact same code on Ruby 2.3.1 and Ruby 2.5.5 and it works perfectly.

It seems like their is a compatibility issue with Ruby 2.6.2.

Any help would be greatly appreciated!

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 21 (10 by maintainers)

Commits related to this issue

Most upvoted comments

Have looked in to this further. The same code runs in rails, but fails in rspec tests, rails console and irb, but only for Ruby 2.6.2

Steps to reproduce in irb:

rvm use 2.5.5
irb
require 'rmagick'
path = "/path/to/file.pdf"
file_blob = open(path, "rb").read
image1 = Magick::Image::from_blob(file_blob) do self.format = 'PDF'; self.density = 144; self.quality = 90 end
 => [ PDF 482x340 482x340+0+0 DirectClass 16-bit 640kb] 

Swap to Ruby 2.6.2

rvm use 2.6.2
irb
require 'rmagick'
path = "/path/to/file.pdf"
file_blob = open(path, "rb").read
image1 = Magick::Image::from_blob(file_blob) do self.format = 'PDF'; self.density = 144; self.quality = 90 end
=> Traceback (most recent call last):
        5: from /Users/work/.rvm/rubies/ruby-2.6.2/bin/irb:23:in `<main>'
        4: from /Users/work/.rvm/rubies/ruby-2.6.2/bin/irb:23:in `load'
        3: from /Users/work/.rvm/rubies/ruby-2.6.2/lib/ruby/gems/2.6.0/gems/irb-1.0.0/exe/irb:11:in `<top (required)>'
        2: from (irb):4
        1: from (irb):4:in `from_blob'
Magick::ImageMagickError (FailedToExecuteCommand `'gs' -sstdout=%stderr -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 '-sDEVICE=pamcmyk32' -dTextAlphaBits=4 -dGraphicsAlphaBits=4 '-r144x144' -dUseCIEColor  '-sOutputFile=/var/folders/gp/74j6yggx6rjf_hdbg2v7fjsw0000gn/T/magick-78909LJ6tiqwpHPxl%d' '-f/var/folders/gp/74j6yggx6rjf_hdbg2v7fjsw0000gn/T/magick-78909Aqvx4zqNjJOg' '-f/var/folders/gp/74j6yggx6rjf_hdbg2v7fjsw0000gn/T/magick-78909-IdybWCTLLg9'' (-1) @ error/deleg)