Class: ChunkyPNG::Image
- Inherits:
-
Object
- Object
- ChunkyPNG::Image
- Defined in:
- lib/chunky_png/image.rb
Instance Attribute Summary collapse
-
#pixel_matrix ⇒ Object
readonly
Returns the value of attribute pixel_matrix.
Class Method Summary collapse
Instance Method Summary collapse
- #[](x, y) ⇒ Object
- #[]=(x, y, pixel) ⇒ Object
- #height ⇒ Object
-
#initialize(width, height, background_color = ChunkyPNG::Pixel::TRANSPARENT) ⇒ Image
constructor
A new instance of Image.
- #pixels ⇒ Object
- #save(filename, constraints = {}) ⇒ Object
- #width ⇒ Object
- #write(io, constraints = {}) ⇒ Object
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_matrix ⇒ Object (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 |
#height ⇒ Object
18 19 20 |
# File 'lib/chunky_png/image.rb', line 18 def height pixel_matrix.height end |
#pixels ⇒ Object
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 |
#width ⇒ Object
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 |