Class: MountableImageServer::ImageProcessor

Inherits:
Object
  • Object
show all
Includes:
Skeptick
Defined in:
lib/mountable_image_server/image_processor.rb

Instance Method Summary collapse

Constructor Details

#initialize(path, parameters) ⇒ ImageProcessor

Returns a new instance of ImageProcessor.



9
10
11
12
# File 'lib/mountable_image_server/image_processor.rb', line 9

def initialize(path, parameters)
  @parameters = parameters
  @path = path
end

Instance Method Details

#run(&block) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/mountable_image_server/image_processor.rb', line 14

def run(&block)
  yield(Pathname(path)) and return unless parameters[:h] || parameters[:w] || parameters[:q]

  Tempfile.create(['processed-image', path.extname]) do |file|
    command = convert(path, to: file.path) do
      set :resize, "#{parameters[:w]}x#{parameters[:h]}>" if parameters[:h] || parameters[:w]
      set :quality, parameters[:q] if parameters[:q]
    end

    command.run

    yield(Pathname(file.path))
  end
end