问题
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?
回答1:
Do you have the jpeg
library installed? http://www.ijg.org/
回答2:
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.
来源:https://stackoverflow.com/questions/2539386/rmagick-returns-nil-reading-jpeg