module

PNG

Constants

MAGIC = Bytes[137, 80, 78, 71, 13, 10, 26, 10]

MAGIC is the first 8 bytes of a PNG file: "\x89PNG\r\n\x1a\n"

VERSION = {{ (`shards version`).stringify.chomp }}

Class methods

chunks(io : IO) : Array(String)

Get a list of the chunks that exist in the png io

Source
palettize(canvas : Canvas) : Canvas

Moves the colors from the image into a PLTE chunk.

Source
read(path : String) : Canvas

Reads a png stream returns a PNG::Canvas

canvas = PNG.read("examples/gradient.png")
canvas.header.color_type # => PNG::ColorType::RGB
canvas[0, 0]             # => Bytes[0, 255, 0]
Source
read(io : IO) : Canvas

Get a list of the chunks that exist in the png io

Source
write(path : String, canvas : Canvas, &heuristic : Scanline | Nil, Scanline -> Scanline)

Write a canvas to a .png file given a path

canvas = PNG::Canvas.new(255, 255)
0.upto(canvas.height - 1) do |y|
  0.upto(canvas.width - 1) do |x|
    canvas[x, y] = Bytes[x, 255, y]
  end
end

PNG.write("examples/gradient.png", canvas)
Source
write(io : IO, canvas : Canvas, &heuristic : Scanline | Nil, Scanline -> Scanline)

Write a canvas to a given io in png format.

Source
write(path : String, canvas : Canvas)
Source
write(io : IO, canvas : Canvas)
Source

Macros

debug(args)

Only logs messages if built with -Dpng-debug

Source

Nested types