“识别”命令不能识别Rails回形针`

时间:2012-11-04 23:15:29

标签: ruby-on-rails ruby-on-rails-3 imagemagick paperclip homebrew

尝试将png保存到带有回形针附件的模型时出错。

我的User型号:

class User < ActieRecord::Base
  attr_accessible :icon
  has_attached_file :icon, :url => "/system/users/icon/:hash.:extension",
    :hash_secret => "superSecretHashSecret",
    :styles => { :medium => "300x300>", :thumb => "100x100>" }
end

尝试设置图标的示例:

u = User.last
u.icon = open(Rails.root + "spec/fixtures/files/example.png")
u.save

示例模型错误:

:icon => ["/var/folders/43/810gn/T/example20121104-36855-1v7t136.png is not recognized by the 'identify' command."]

有很多人向此发布了类似的问题,尤其是this one,但这些解决方案都不适合我。

我的command_path设置正确:

O:~ $ which identify
/usr/local/bin/identify

development.rb

Paperclip.options[:command_path] = "/usr/local/bin/"

但这仍然可能是问题。 当试图直接使用`识别时,我得到以下错误:

O:~ $ identify workspace/app/spec/fixtures/files/example.png 
dyld: Library not loaded: /usr/lib/libltdl.7.dylib
  Referenced from: /usr/local/bin/identify
  Reason: image not found
Trace/BPT trap: 5

有关于此处发生了什么的任何建议吗?

我尝试重新安装ImageMagick

brew unlink imagemagick
brew install imagemagick

其他人建议添加Rmagick。绝对不是使用Paperclip的要求,它也没有帮助。

建议的另一个解决方案是删除:style属性。但这不是解决方案。我需要对图像进行处理。

我让Paperclip在我的项目中处理另一个模型,该模型处理的文档不是图像/不进行任何处理。所以我知道这可能与此有关。

有关如何解决此问题的其他任何建议?

4 个答案:

答案 0 :(得分:9)

这是一个ImageMagick安装问题。

首先尝试

brew update
brew upgrade imagemagick

如果这不起作用,请使用 magick-installer 脚本来解决此问题: https://github.com/maddox/magick-installer

curl https://raw.github.com/maddox/magick-installer/master/magick-installer.sh | sh

或者,使用 magick-installer 的分支与较新版本的依赖库:

curl https://raw.github.com/GTSouza/magick-installer/master/magick-installer.sh | sh

答案 1 :(得分:4)

最终解决方案是安装libtool。这也是最好的建议here。我的问题证明更复杂,因为homebrew没有更新,并且处于无法在不强制结账的情况下无法更新的状态。

对于将来遇到此问题的人,我建议手动检查identify命令是否确实有效,即使它在您的路径中。

identify /path/to/some/image

如果失败,它将显示如下内容:

O:~ $ identify workspace/app/spec/fixtures/files/example.png 
dyld: Library not loaded: /usr/lib/libltdl.7.dylib
  Referenced from: /usr/local/bin/identify
  Reason: image not found
Trace/BPT trap: 5

在这种情况下,请尝试安装libtool

brew install libtool

如果失败,请运行brew update。如果它仍然失败,请确保安装了最新的Xcode并再次尝试更新。

如果您可以成功使用identity,您将知道这有效。它看起来像这样:

O:~ $ identify ~/workspace/app/spec/fixtures/files/example.png 
~/workspace/app/spec/fixtures/files/example.png PNG 200x201 200x201+0+0 8-bit DirectClass 66.1KB 0.000u 0:00.000

glebm的回答可能也很有效。我没看过那个安装程序。

答案 2 :(得分:0)

这可能是由于使用旧版本的Paperclip与可卡因宝石的新版本和不兼容版本造成的。您可以使用bundle update paperclip更新paperclip gem版本。它将根据兼容性更新回形针和可卡因版本。

https://github.com/thoughtbot/paperclip/issues/1038

答案 3 :(得分:0)

我在Mac上升级到Mavericks后遇到了同样的问题。

以下是解决问题的步骤:

brew update
brew install libtool
brew link libtool
brew upgrade imagemagick