Class: ChunkyPNG::Image

Inherits:
Object
  • Object
show all
Defined in:
lib/chunky_png/image.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(width, height, background_color = ChunkyPNG::Pixel::TRANSPARENT) ⇒ Image

Returns a new instance of Image.



6
7
8
# File 'lib/chunky_png/image.rb', line 6

def initialize(width, height, background_color = ChunkyPNG::Pixel::TRANSPARENT)
  @pixel_matrix = ChunkyPNG::PixelMatrix.new(width, height, background_color)
end

Instance Attribute Details

#pixel_matrixObject (readonly)

Returns the value of attribute pixel_matrix.



4
5
6
# File 'lib/chunky_png/image.rb', line 4

def pixel_matrix
  @pixel_matrix
end

Class Method Details

.from_pixel_matrix(matrix) ⇒ Object



10
11
12
# File 'lib/chunky_png/image.rb', line 10

def self.from_pixel_matrix(matrix)
  self.new(matrix.width, matrix.height, matrix.pixels)
end

Instance Method Details

#[](x, y) ⇒ Object



22
23
24
# File 'lib/chunky_png/image.rb', line 22

def [](x, y)
  pixel_matrix[x,y]
end

#[]=(x, y, pixel) ⇒ Object



26
27
28
# File 'lib/chunky_png/image.rb', line 26

def []=(x, y, pixel)
  pixel_matrix[x,y] = pixel
end

#heightObject



18
19
20
# File 'lib/chunky_png/image.rb', line 18

def height
  pixel_matrix.height
end

#pixelsObject



30
31
32
# File 'lib/chunky_png/image.rb', line 30

def pixels
  pixel_matrix.pixels
end

#save(filename, constraints = {}) ⇒ Object



39
40
41
# File 'lib/chunky_png/image.rb', line 39

def save(filename, constraints = {})
  File.open(filename, 'w') { |io| write(io, constraints) }
end

#widthObject



14
15
16
# File 'lib/chunky_png/image.rb', line 14

def width
  pixel_matrix.width
end

#write(io, constraints = {}) ⇒ Object



34
35
36
37
# File 'lib/chunky_png/image.rb', line 34

def write(io, constraints = {})
  datastream = pixel_matrix.to_datastream(constraints)
  datastream.write(io)
end