0

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?

Yarin
  • 173,523
  • 149
  • 402
  • 512
  • Are you using the same version of ImageMagick/RMagick on both machines? – dlemstra Jul 15 '14 at 10:18
  • @dlemstra - Same version of RMagick (2.13.2) though just noticed that ImageMagick on my Mac is version 6.8.0-10 while Heroku is running version 6.5.7-8, though there's nothing in the ImageMagick change log that would indicate that matters – Yarin Jul 15 '14 at 20:36
  • The `identify` check that @Adriano suggested is the best way to find out, but still, can you try using [MiniMagick](https://github.com/minimagick/minimagick) and see what that outputs? They both use the same ImageMagick but still just curious. – Subhas Jul 16 '14 at 07:13

3 Answers3

2

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?

Adriano Tadao
  • 976
  • 1
  • 10
  • 12
  • Thanks, I checked this and while the format returns correctly on both platforms for local images, it fails on Heroku for remote images- see my answer for details. – Yarin Jul 16 '14 at 17:45
1

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.

Community
  • 1
  • 1
Yarin
  • 173,523
  • 149
  • 402
  • 512
0

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.

Carlos Cervantes
  • 1,377
  • 1
  • 10
  • 16