diff --git a/lib/compass/sass_extensions/sprites/engines/chunky_png_engine.rb b/lib/compass/sass_extensions/sprites/engines/chunky_png_engine.rb index dd7a6455..c26caa11 100644 --- a/lib/compass/sass_extensions/sprites/engines/chunky_png_engine.rb +++ b/lib/compass/sass_extensions/sprites/engines/chunky_png_engine.rb @@ -7,20 +7,19 @@ end module Compass module SassExtensions module Sprites - module ChunkyPngEngine - - # Returns a PNG object + class ChunkyPngEngine < Compass::SassExtensions::Sprites::Engine + def construct_sprite - output_png = ChunkyPNG::Image.new(width, height, ChunkyPNG::Color::TRANSPARENT) + @canvas = ChunkyPNG::Image.new(width, height, ChunkyPNG::Color::TRANSPARENT) images.each do |image| input_png = ChunkyPNG::Image.from_file(image.file) if image.repeat == "no-repeat" - output_png.replace! input_png, image.left, image.top + canvas.replace! input_png, image.left, image.top else x = image.left - (image.left / image.width).ceil * image.width while x < width do begin - output_png.replace! input_png, x, image.top + canvas.replace! input_png, x, image.top x += image.width rescue ChunkyPNG::OutOfBounds break; @@ -28,8 +27,15 @@ module Compass end end end - output_png + end + + def save(filename) + if canvas.nil? + construct_sprite + end + canvas.save(filename, :best_compression) end + end end end