Class: Compass::SassExtensions::Sprites::ChunkyPngEngine

Inherits:
Engine
  • Object
show all
Defined in:
lib/compass/sass_extensions/sprites/engines/chunky_png_engine.rb

Instance Attribute Summary

Attributes inherited from Engine

#canvas, #height, #images, #width

Instance Method Summary collapse

Methods inherited from Engine

#initialize

Constructor Details

This class inherits a constructor from Compass::SassExtensions::Sprites::Engine

Instance Method Details

#construct_spriteObject



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/compass/sass_extensions/sprites/engines/chunky_png_engine.rb', line 12

def construct_sprite
  @canvas = ChunkyPNG::Image.new(width, height, ChunkyPNG::Color::TRANSPARENT)
  images.each do |image|
    input_png = begin
      ChunkyPNG::Image.from_file(image.file)
    rescue ChunkyPNG::SignatureMismatch
      raise Compass::SpriteException, "You have provided a file that does not have a PNG signature. Only PNG files are supported by the default sprite engine"
    end
    canvas.replace! input_png, image.left, image.top
  end
end

#save(filename) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/compass/sass_extensions/sprites/engines/chunky_png_engine.rb', line 24

def save(filename)
  if canvas.nil?
    construct_sprite
  end
  
  canvas.save(filename,  Compass.configuration.chunky_png_options)
end