Search code examples
ruby-on-railsrubyherokuimagemagickrmagick

RMagick image type detection failing on Heroku


We're using RMagick to identify image types in cases where the file extensions are unavailable or wrong. The format attribute works on my local Mac dev box, but on Heroku it returns nil...

irb> require 'RMagick'
irb> image = Magick::Image::read('https://s3.amazonaws.com/com.appgrinders.test/images/dog.gif')[0]
irb> image.format
=> nil

Any ideas?


Solution

  • Apparently this is due to ImageMagick not being able to read remote images (See here) though strangely the problem only manifests itself on Heroku(?). The underlying ImageMagick format returns 'HTTPS', while RMagick format returns nil.

    On my Mac:

    $ identify -verbose https://s3.amazonaws.com/com.appgrinders.test/images/dog.gif
    
    Format: GIF (CompuServe graphics interchange format)
    ...
    

    On Heroku:

    $ identify -verbose https://s3.amazonaws.com/com.appgrinders.test/images/dog.gif
    
    Format: HTTPS
    ...
    

    So then the answer is to copy the image locally and read it there.