For info, I also followed this
source, and it works perfectly (see below code).
Nevertheless, I have a small question, I'm totally new in ruby and I'd like to pass the image size (here 500x375) in parameter.
How would I call it then ??
I tried :
image_tag p.file.process(:convert_to_canvas_size(500x375)).url
But it didn't work ...
1. config/initializers/dragonfly.rb
require 'image_processor'
app = Dragonfly[:images]
app.processor.register(ImageProcessor)
2. image_processor.rb
class ImageProcessor
def convert_to_canvas_size_500x375(temp_object)
tempfile = new_tempfile
args = " #{temp_object.path} -resize 500x375 -gravity center -background grey -extent 500x375 #{tempfile.path}"
full_command = "convert #{args}"
result = `#{full_command}`
tempfile
end
private
def new_tempfile(ext=nil)
tempfile = ext ? Tempfile.new(['dragonfly', ".#{ext}"]) : Tempfile.new('dragonfly')
tempfile.binmode
tempfile.close
tempfile
end
end
3. call it :
image_tag p.file.process(:convert_to_canvas_size_500x375).url