module PNG
Defined in:
png.crpng/canvas.cr
png/chunk.cr
png/colors.cr
png/colors/gray.cr
png/colors/gray_alpha.cr
png/colors/hsv.cr
png/colors/rgb.cr
png/colors/rgba.cr
png/enums/color_type.cr
png/enums/compression_method.cr
png/enums/filter_method.cr
png/enums/filter_type.cr
png/enums/interlacing.cr
png/error.cr
png/filter.cr
png/header.cr
png/heuristic.cr
png/inflater.cr
png/packed_data.cr
png/palette.cr
png/parser.cr
png/pixel_size.cr
png/scanline.cr
Constant Summary
-
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 Method Summary
-
.read(path : String) : Canvas
Reads a png stream returns a PNG::Canvas
-
.read(io : IO) : Canvas
Reads a png stream returns a PNG::Canvas
-
.write(path : String, canvas : Canvas, &heuristic : Scanline | Nil, Scanline -> Scanline)
Write a canvas to a .png file given a path
-
.write(io : IO, canvas : Canvas, &heuristic : Scanline | Nil, Scanline -> Scanline)
Write a canvas to a given io in png format.
- .write(path : String, canvas : Canvas)
- .write(io : IO, canvas : Canvas)
Macro Summary
-
debug(args)
Only logs messages if built with
-Dpng-debug
Class Method Detail
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]
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]
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)
Write a canvas to a given io in png format.