我正在尝试允许对我的应用进行裁剪。但是,当我运行此方法时:
def avatar_geometry(style = :original)
@geometry ||= {}
@geometry[style] ||= Paperclip::Geometry.from_file avatar.path(style)
end
identify: unable to open image `/original/4/nutra.jpg': No such file or directory @ error/blob.c/OpenBlob/2587.
Paperclip::NotIdentifiedByImageMagickError: /original/4/nutra.jpg is not recognized by the 'identify' command.
from /Users/skline/.rvm/gems/ruby-1.9.2-p180@nutra/gems/paperclip-cloudfiles-2.3.10.1/lib/paperclip/geometry.rb:26:in `from_file'
from /Users/skline/NutraNation1/app/models/user.rb:111:in `avatar_geometry'
from (irb):2
from /Users/skline/.rvm/gems/ruby-1.9.2-p180@nutra/gems/railties-3.0.7/lib/rails/commands/console.rb:44:in `start'
from /Users/skline/.rvm/gems/ruby-1.9.2-p180@nutra/gems/railties-3.0.7/lib/rails/commands/console.rb:8:in `start'
from /Users/skline/.rvm/gems/ruby-1.9.2-p180@nutra/gems/railties-3.0.7/lib/rails/commands.rb:23:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
Paperclip 中有问题的代码如下所示:
def self.from_file file
file = file.path if file.respond_to? "path"
geometry = begin
Paperclip.run("identify", "-format %wx%h :file", :file => "#{file}[0]")
rescue Cocaine::ExitStatusError
""
rescue Cocaine::CommandNotFoundError => e
raise Paperclip::CommandNotFoundError.new("Could not run the `identify` command. Please install ImageMagick.")
end
parse(geometry) ||
raise(NotIdentifiedByImageMagickError.new("#{file} is not recognized by the 'identify' command."))
end
我的头像模型如下所示:
AVATAR_SW = 55
AVATAR_SH = 55
AVATAR_NW = 240
AVATAR_NH = 240
has_attached_file :avatar,
:styles => { :normal => ["#{AVATAR_NW}x#{AVATAR_NH}>", :jpg],
:small => ["#{AVATAR_SW}x#{AVATAR_SH}#", :jpg] }, :storage => :s3,
:s3_credentials => "#{RAILS_ROOT}/config/s3.yml",
:path => "/:style/:id/:filename"
我给 Paperclip 在我的 development.rb 中找到 ImageMagick 的路线是这样的:Paperclip.options[:command_path] = "/usr/local/bin/"
我已经验证它确实是 ImageMagick 的家。
有趣的是,我可以毫无问题地上传图片。只是当我尝试运行此方法以裁剪它们时,我遇到了问题。有什么建议么。使用回形针 (2.3.11)