如何告诉Paperclip在上传时不要保存原始文件,或者更好的是将缩放后的文件作为原始文件存储?
如何告诉Paperclip在上传时不要保存原始文件,或者更好的是将缩放后的文件作为原始文件存储?
我认为你可以简单地定义一个样式来控制:original大小,从而使用paperclip替换原始图片。
:styles => { :original => '300x168>', :cropped_thumb => {:geometry => "115x70#", :jcrop => true}, ...}
after_save :reprocess_attach
private
def reprocess_attach
if self.<atch_name>.present? && Pathname.new(self.<atch_name>.path).exist?
self.<atch_name>.save
File.unlink(self.<atch_name>.path)
end
end
IT并不关心在舞台背后进行了什么处理。它只是删除原始文件。
默认情况下,Paperclip始终保存原始文件,但我认为,如果您只是从迁移中删除它,则不会尝试保存它。
我在我的模型上保存了一个缩放的原始文件,以便用户稍后可以编辑其图像。我的模型如下:
:styles => { :cropped_thumb => {:geometry => "115x70#", :jcrop => true}, :resized_thumb => {:geometry => "115x70>"}, :deal => {:geometry => "64x56#"},
:cropped_large => {:geometry => "#{PHOTO_IMAGE_WIDTH}x#{PHOTO_IMAGE_HEIGHT}#", :jcrop => true},
:resized_large => {:geometry => "#{PHOTO_IMAGE_WIDTH}x#{PHOTO_IMAGE_HEIGHT}>"},
:orig => '300x168>', #this is the scaled original that I call later
:cropped_orig => {:geometry => '300x168#', :jcrop => true},
:resized_orig => {:geometry => '300x168>'} },
:processors => [:jcropper]