我希望在上传文件时获取图片的尺寸信息。我通过模型使用提取图像尺寸来实现这一点。但是,我想通过自定义处理器来完成这个任务。我尝试了以下代码:
Player.rbclass Player < ActiveRecord::Base
has_attached_file :avatar, processors: [:custom], :style => {:original => {}}
....
end
/lib/paperclip_processors/custom.rb
module Paperclip
class Custom < Processor
def initialize file, options = {}, attachment = nil
super
@file = file
@attachment = attachment
@current_format = File.extname(@file.path)
@format = options[:format]
@basename = File.basename(@file.path, @current_format)
end
def make
temp_file = Tempfile.new([@basename, @format])
#geometry = Paperclip::Geometry.from_file(temp_file)
temp_file.binmode
if @is_polarized
run_string = "convert #{fromfile} -thumbnail 300x400 -bordercolor white -background white +polaroid #{tofile(temp_file)}"
Paperclip.run(run_string)
end
temp_file
end
def fromfile
File.expand_path(@file.path)
end
def tofile(destination)
File.expand_path(destination.path)
end
end
end
我从这里获取了上面(custom.rb)的代码。 是否可能实现此目标?如何实现?谢谢提前 :)
Paperclip::Custom
处理器得到了什么结果? - czak