Class: Acbaker::Processors::Cover

Inherits:
Base
  • Object
show all
Defined in:
lib/acbaker/processors/cover.rb

Instance Attribute Summary

Attributes inherited from Base

#asset_pack, #options

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Acbaker::Processors::Base

Instance Method Details

#defaultsObject



4
5
6
# File 'lib/acbaker/processors/cover.rb', line 4

def defaults
  { "background-color" => "#FFFFFF", "gravity" => "Center" }
end

#run(image, image_spec, width = nil, height = nil) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/acbaker/processors/cover.rb', line 8

def run(image, image_spec, width = nil, height = nil)
  # resize image
  image.change_geometry("#{width}x#{height}^") do |px, py, i|
    image.resize!(px, py)
  end

  # crop image
  canvas = Magick::Image.new(width, height)
  if @options['background-color'] == :transparent
    canvas = canvas.matte_floodfill(1, 1)
  else
    canvas = canvas.color_floodfill(1, 1, Magick::Pixel.from_color(@options['background-color']))
  end

  # place image
  gravity_string = "Magick::#{@options['gravity']}Gravity"
  gravity = Object.const_get(gravity_string)
  canvas.composite(image, gravity, Magick::OverCompositeOp)
end