Sha256: ffef3c45b5b962fe1b0100f79bc94e972bf1debc55310d9cc5f5b43374f30c83

Contents?: true

Size: 897 Bytes

Versions: 3

Compression:

Stored size: 897 Bytes

Contents

module ChunkyPNG
  class Image
    
    attr_reader :pixel_matrix
    
    def initialize(width, height, background_color = ChunkyPNG::Pixel::TRANSPARENT)
      @pixel_matrix = ChunkyPNG::PixelMatrix.new(width, height, background_color)
    end
    
    def self.from_pixel_matrix(matrix)
      self.new(matrix.width, matrix.height, matrix.pixels)
    end
    
    def width
      pixel_matrix.width
    end
    
    def height
      pixel_matrix.height
    end
    
    def [](x, y)
      pixel_matrix[x,y]
    end

    def []=(x, y, pixel)
      pixel_matrix[x,y] = pixel
    end
    
    def pixels
      pixel_matrix.pixels
    end
    
    def write(io, constraints = {})
      datastream = pixel_matrix.to_datastream(constraints)
      datastream.write(io)
    end
    
    def save(filename, constraints = {})
      File.open(filename, 'w') { |io| write(io, constraints) }
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
chunky_png-0.0.5 lib/chunky_png/image.rb
chunky_png-0.0.4 lib/chunky_png/image.rb
chunky_png-0.0.3 lib/chunky_png/image.rb