RMagick returns nil reading JPEG

荒凉一梦 提交于 2019-12-23 04:43:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!