Module: SpriteFactory::Library::ChunkyPng

Defined in:
lib/sprite_factory/library/chunky_png.rb

Constant Summary collapse

VALID_EXTENSIONS =
:png

Class Method Summary collapse

Class Method Details

.create(filename, images, width, height) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/sprite_factory/library/chunky_png.rb', line 21

def self.create(filename, images, width, height)
  target = ChunkyPNG::Image.new(width, height, ChunkyPNG::Color::TRANSPARENT)
  images.each do |image|
    target.compose!(image[:image], image[:x], image[:y])
  end
  target.save(filename)
end

.load(files) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/sprite_factory/library/chunky_png.rb', line 9

def self.load(files)
  files.map do |filename|
    image = ChunkyPNG::Image.from_file(filename)
    {
      :filename => filename,
      :image    => image,
      :width    => image.width,
      :height   => image.height
    }
  end
end