我使用Paperclip Jcrop时出错,我按照rails cast进行操作。 当我上传图像时它可以正常工作,但是当我尝试裁剪它时,我会在我的控制台中找到它:
[paperclip] An error was received while processing: #<Paperclip::PaperclipError: There was an error processing the thumbnail for paperclip-reprocess20110822-2281-19969sz>
[paperclip] An error was received while processing: #<Paperclip::PaperclipError: There was an error processing the thumbnail for paperclip-reprocess20110822-2281-19969sz>
有我的模特:
class User < ActiveRecord::Base
has_attached_file :avatar, :styles => { :small => ["100x100#", :jpg], :large => ["500x500>",:jpg] }, :processors => [:cropper]
attr_accessor :crop_x, :crop_y, :crop_w, :crop_h
after_update :reprocess_avatar, :if => :cropping?
def cropping?
!crop_x.blank? && !crop_y.blank? && !crop_w.blank? && !crop_h.blank?
end
def avatar_geometry(style = :original)
@geometry ||= {}
@geometry[style] ||= Paperclip::Geometry.from_file(avatar.path(style))
end
private
def reprocess_avatar
avatar.reprocess!
end
end
我的处理器:
module Paperclip
class Cropper < Thumbnail
def transformation_command
if crop_command
crop_command + super.first.sub(/ -crop \S+/, '')
else
super
end
end
def crop_command
target = @attachment.instance
if target.cropping?
" -crop #{target.crop_w}x#{target.crop_h}+#{target.crop_x}+#{target.crop_y}"
end
end
end
end
有什么想法解决这个问题吗? (我在OS 10.7上)
答案 0 :(得分:2)
在模型中
#has_attached_file :avatar, :styles => { :small => ["100x100#", :jpg], :large => ["500x500>",:jpg] }, :processors => [:cropper]
has_attached_file :avatar, :styles => {
:small => {:geometry => "100x100#", :processors => [:cropper]},
:large => {:geometry => "500x500>"}
}
在处理器中
#crop_command + super.sub(/ -crop \S+/, '')
crop_command + super.join(' ').sub(/ -crop \S+/, '').split(' ')