Class: Compass::SassExtensions::Sprites::RmagickEngine

Inherits:
Engine
  • Object
show all
Defined in:
lib/compass-rmagick-engine.rb

Instance Method Summary collapse

Instance Method Details

#construct_spriteObject



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

def construct_sprite
  @canvas = Magick::Image.new(width, height) {
    self.background_color = 'none'
  }
  @canvas.format = 'PNG24'
  images.each do |image|
    input_png = Magick::Image.read(image.file).first
    if image.repeat == "no-repeat"
      @canvas = composite_images(@canvas, input_png, image.left, image.top)
    else
      x = image.left - (image.left / image.width).ceil * image.width
      while x < width do
        @canvas = composite_images(@canvas, input_png, x, image.top)
        x += image.width
      end
    end
  end
  @canvas
end

#save(filename) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/compass-rmagick-engine.rb', line 28

def save(filename)
  if canvas.nil?
    construct_sprite
  end

  canvas.write(filename)
end