开发者

ImageMagick and Paperclip not finding the location of my files on S3 (Jcrop)

I am trying to allowing cropping on my app. However, when I run this method:

  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 'id开发者_如何学Pythonentify' 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>'

The offending piece of code in Paperclip looks like this:

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

My model for the avatar looks like this:

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"

And the route I give to Paperclip to find ImageMagick in my development.rb is this: Paperclip.options[:command_path] = "/usr/local/bin/" which I have verified is indeed the home of ImageMagick.

The interesting thing is that I can upload images without any problem. It is simply when I try to run this method in order to crop them that I run into problems. Any suggestions. Using paperclip (2.3.11)


This works for s3 and local

def photo_geometry(style = :original)
  @geometry ||= {}
  path = (avatar.options[:storage]==:s3) ? avatar.url(style) : avatar.path(style)
  @geometry[style] ||= Paperclip::Geometry.from_file(path)
end
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜