views:

100

answers:

2

When I try to open a JPEG format file in Rails using RMagick, it always return nil with any jpg file. Other file formats open well.

$ script/console
Loading development environment (Rails 2.3.4)
>> require 'RMagick'
>> img = Image.read("1.gif").first
=> 1.gif GIF 230x100 230x100+0+0 PseudoClass 256c 8-bit 2kb
>> img = Image.read("1.png").first
=> 1.png PNG 1280x800 1280x800+0+0 DirectClass 8-bit 156kb
>> img = Image.read("1.jpg").first
=> nil

Why this happens?

A: 

Do you have the jpeg library installed? http://www.ijg.org/

Jonathan Julian
yes, I reinstalled the libjpeg library to version 8a, the same result.
Yuri
I'm running `RMagick 2.12.2`. In irb, `require 'RMagick'`,then `Magick::Image.read('abc.jpg')` returns `=> [abc.jpg JPEG 2000x1003 2000x1003+0+0 DirectClass 8-bit 1409kb]`.
Jonathan Julian
A: 

Hey there John,

I am assuming you have tested other jpgs and they are all returning null?

You might want to try the 'identify' command at your bash prompt (not in irb) to test imagemagick and make sure it isn't returning null on the jpg.

I have had trouble with Rmagick using the wrong build of imagemagick and had to recompile my libraries.

Other than that, you may be dealing with a corrupt .jpg file that didn't have its headers saved properly.

Dustin M.
identify 1.jpg1.jpg JPEG 3072x2304 3072x2304+0+0 8-bit DirectClass 2.692MiB 0.000u 0:00.010This means that I have broken RMagick? Yes, theese jpegs open well with RMagick on my hosting site.I reinstalled RMagick, but it didn't help.
Yuri
Yuri, That IS odd, if you have sudo access nav to your root folder and run this: "sudo find . | grep identify" Just to make sure there aren't multiple identify binaries. It does appear that something is wrong with your RMagick build. It doesn't seem to be finding the jpeg libraries. If you find more than one identify binary you might want to remove the gem, and imagemagick, and reinstall all of them from scratch. Not exactly fun I know.
Dustin M.