Yarin
Yarin

Reputation: 183619

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?

Upvotes: 0

Views: 988

Answers (3)

Carlos Cervantes
Carlos Cervantes

Reputation: 1447

For me it was as easy as removing the https in the s3 url for the image I was trying to convert.

image_url = image_url.gsub('https://', 'http')

Now I can convert any image. My bucket can serve content from http and https.

Upvotes: 0

Yarin
Yarin

Reputation: 183619

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.

Upvotes: 1

Adriano Tadao
Adriano Tadao

Reputation: 986

If you take a look on ImageMagick page, you can see the command responsible for these informations about the image file.

http://www.imagemagick.org/script/identify.php

Do you tried run the command identify in Heroku console?

Look:

$  identify image.jpg
=> image.jpg JPEG 960x960 960x960+0+0 8-bit sRGB 89KB 0.010u 0:00.009

or:

$ identify -verbose image.jpg 

Image: image.jpg
Format: JPEG (Joint Photographic Experts Group JFIF format)
Mime type: image/jpeg
Class: DirectClass
Geometry: 960x960+0+0
Units: Undefined
Type: TrueColor
Endianess: Undefined
Colorspace: sRGB
Depth: 8-bit
Channel depth:

Can you upgrade the ImageMagick on the Heroku?

Upvotes: 2

Related Questions