Rails的paperclip“未被'identify'命令识别”。

4

在试图将png保存到具有附加的paperclip模型时,我遇到了错误。

我的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."]

有很多人发布了类似于这个问题的帖子,特别是这个,但是那些解决方案对我都不起作用。

我的command_path已经正确设置:

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

development.rb 文件中。
Paperclip.options[:command_path] = "/usr/local/bin/"

这可能仍然是问题所在。 当尝试直接使用 `identify 时,我会收到以下错误:

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个回答

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

谢谢glebm。我通过直接与homebrew折腾了一段时间,终于让它工作了(不过看起来这样做可能会省去我的麻烦)。 - Andrew Hubbs

5
解决方案是安装 libtool。这也是这里提出的最佳建议。我的问题变得更加复杂,因为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的答案可能也很有效。但我没有查看过该安装程序。


0

这可能是由于使用旧版本的Paperclip与较新且不兼容的Cocaine gem版本造成的。您可以通过使用bundle update paperclip来更新paperclip gem版本。它将根据兼容性更新paperclip和cocaine版本。

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


0

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

以下是解决问题的步骤:

brew update
brew install libtool
brew link libtool
brew upgrade imagemagick

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接