Module: ChunkyPNG::Canvas::PNGEncoding
- Included in:
- ChunkyPNG::Canvas
- Defined in:
- lib/chunky_png/canvas/png_encoding.rb
Overview
Methods for encoding a Canvas into a PNG datastream
Constant Summary collapse
- TRUECOLOR_ENCODER =
lambda { |color| Color.to_truecolor_bytes(color) }
- TRUECOLOR_ALPHA_ENCODER =
lambda { |color| Color.to_truecolor_alpha_bytes(color) }
- GRAYSCALE_ENCODER =
lambda { |color| Color.to_grayscale_bytes(color) }
- GRAYSCALE_ALPHA_ENCODER =
lambda { |color| Color.to_grayscale_alpha_bytes(color) }
Instance Method Summary collapse
- #save(filename, constraints = {}) ⇒ Object
- #to_blob(constraints = {}) ⇒ Object (also: #to_string, #to_s)
-
#to_datastream(constraints = {}) ⇒ Object
Converts this Canvas to a datastream, so that it can be saved as a PNG image.
- #write(io, constraints = {}) ⇒ Object
Instance Method Details
#save(filename, constraints = {}) ⇒ Object
17 18 19 |
# File 'lib/chunky_png/canvas/png_encoding.rb', line 17 def save(filename, constraints = {}) File.open(filename, 'wb') { |io| write(io, constraints) } end |
#to_blob(constraints = {}) ⇒ Object Also known as: to_string, to_s
21 22 23 |
# File 'lib/chunky_png/canvas/png_encoding.rb', line 21 def to_blob(constraints = {}) to_datastream(constraints).to_blob end |
#to_datastream(constraints = {}) ⇒ Object
Converts this Canvas to a datastream, so that it can be saved as a PNG image.
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/chunky_png/canvas/png_encoding.rb', line 30 def to_datastream(constraints = {}) data = encode_png(constraints) ds = Datastream.new ds.header_chunk = Chunk::Header.new(data[:header]) ds.palette_chunk = data[:palette_chunk] if data[:palette_chunk] ds.transparency_chunk = data[:transparency_chunk] if data[:transparency_chunk] ds.data_chunks = Chunk::ImageData.split_in_chunks(data[:pixelstream]) ds.end_chunk = Chunk::End.new return ds end |
#write(io, constraints = {}) ⇒ Object
13 14 15 |
# File 'lib/chunky_png/canvas/png_encoding.rb', line 13 def write(io, constraints = {}) to_datastream(constraints).write(io) end |