Class: Paperclip::Caption
- Inherits:
-
Processor
- Object
- Processor
- Paperclip::Caption
- Defined in:
- lib/caption_paperclip_processor.rb
Instance Method Summary collapse
-
#initialize(file, options = {}, attachment = nil) ⇒ Caption
constructor
A new instance of Caption.
- #make ⇒ Object
Constructor Details
#initialize(file, options = {}, attachment = nil) ⇒ Caption
Returns a new instance of Caption.
6 7 8 9 10 11 12 13 |
# File 'lib/caption_paperclip_processor.rb', line 6 def initialize file, = {}, = nil super @file = file @format = [:format] @current_format = File.extname(@file.path) @basename = File.basename(@file.path, @current_format) end |
Instance Method Details
#make ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/caption_paperclip_processor.rb', line 15 def make src = @file dst = Tempfile.new([@basename, @format].compact.join(".")) dst.binmode begin parameters = [] parameters << parameters << parameters << ":source" parameters << "+swap" parameters << "-gravity center" parameters << "-composite" parameters << ":dest" parameters = parameters.flatten.compact.join(" ").strip.squeeze(" ") success = convert(parameters, source: "#{File.(src.path)}[0]", dest: File.(dst.path)) rescue Cocaine::ExitStatusError => e raise Paperclip::Error, "There was an error processing caption for #{@basename}" if @whiny rescue Cocaine::CommandNotFoundError => e raise Paperclip::Errors::CommandNotFoundError.new("Could not run the `convert` command. Please install ImageMagick.") end dst end |