refactored engine to be a class and turned on best compression for chunky_png
This commit is contained in:
parent
6f95c9d17a
commit
b6cf4f5213
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user