RMagick返回零读取JPEG [英] RMagick returns nil reading JPEG
问题描述
当我尝试使用RMagick在Rails中打开JPEG格式文件时,它总是返回任何jpg文件的nil。其他文件格式打开很好。
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
为什么会这样?
推荐答案
我假设您已经测试了其他jpgs并且它们都返回null?
I am assuming you have tested other jpgs and they are all returning null?
您可能想尝试'识别'命令你的bash提示符(不是irb)来测试imagemagick并确保它没有在jpg上返回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.
我在使用错误的构建时遇到了Rmagick的问题imagemagick并且不得不重新编译我的库。
I have had trouble with Rmagick using the wrong build of imagemagick and had to recompile my libraries.
除此之外,你可能正在处理一个没有正确保存标题的损坏的.jpg文件。
Other than that, you may be dealing with a corrupt .jpg file that didn't have its headers saved properly.
这篇关于RMagick返回零读取JPEG的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!