Skip to content
Browse files

hackey spikey first stab at replacing our png parser with chunky_png

  • Loading branch information...
1 parent af1d4fc commit 8ee57700e643746342b626a593e84593cfdef8d8 @aberant committed Jan 16, 2011
Showing with 37 additions and 0 deletions.
  1. +1 −0 lib/css-spriter.rb
  2. +36 −0 lib/css-spriter/chunky_sprite.rb
View
1 lib/css-spriter.rb
@@ -9,6 +9,7 @@
require 'css-spriter/png/iend'
require 'css-spriter/png/image'
require 'css-spriter/sprite'
+require 'css-spriter/chunky_sprite'
require 'css-spriter/directory_processor'
require 'css-spriter/stylesheet_builder'
require 'css-spriter/processor'
View
36 lib/css-spriter/chunky_sprite.rb
@@ -0,0 +1,36 @@
+require 'chunky_png'
+
+class ChunkySprite
+ attr_reader :images, :max_height
+
+ def initialize
+ @images = []
+ @locations = {}
+ end
+
+ def append( image )
+ @images << image
+ end
+
+ def append_file( filename )
+ append( ChunkyPNG::Image.from_file( filename ))
+ end
+
+ def write( output_filename )
+ return if @images.empty?
+
+ sprite_height = @images.map{ |i| i.height }.max
+ sprite_width = @images.inject(0){|sum, image| sum + image.width }
+
+ sprite = ChunkyPNG::Image.new(sprite_width, sprite_height)
+
+ current_x = 0
+
+ images.each do |image|
+ sprite.replace(image, current_x, 0)
+ current_x += image.width
+ end
+
+ sprite.save( output_filename, :best_compression )
+ end
+end

0 comments on commit 8ee5770

Please sign in to comment.
Something went wrong with that request. Please try again.