StumpyPNG.read(path : String) : Canvas
read a PNG image file from a pathStumpyPNG.read(io : IO) : Canvas
read a PNG image file from any IO objectStumpyPNG.write(canvas, path : String, bit_depth: 16, color_type: :rgb_alpha)
save a canvas as a PNG image fileStumpyPNG.write(canvas, io : IO, bit_depth: 16, color_type: :rgb_alpha)
write a canvas as PNG data to any IO objectbit_depth
is optional, valid values are8
and16
(default)color_type
is optional, valid values are:grayscale
,:grayscale_alpha
,:rgb
and:rgb_alpha
(default)
StumpyPNG::PNG
, helper class to store some state while parsing PNG filesCanvas
andRGBA
from stumpy_core
shards init
- Add the dependency to the
shard.yml
file
...
dependencies:
stumpy_png:
github: stumpycr/stumpy_png
version: "~> 5.0"
...
shards install
require "stumpy_png"
canvas = StumpyPNG.read("foo.png")
r, g, b = canvas[0, 0].to_rgb8
puts "red=#{r}, green=#{g}, blue=#{b}"
require "stumpy_png"
include StumpyPNG
canvas = Canvas.new(256, 256)
(0..255).each do |x|
(0..255).each do |y|
# RGBA.from_rgb_n(values, bit_depth) is an internal helper method
# that creates an RGBA object from a rgb triplet with a given bit depth
color = RGBA.from_rgb_n(x, y, 255, 8)
canvas[x, y] = color
end
end
StumpyPNG.write(canvas, "rainbow.png")
(See examples/
for more examples)
- Grayscale
- Grayscale + Alpha
- RGB
- RGB + Alpha
- Palette
- None
- Sub
- Up
- Average
- Paeth
- None
- Adam7
None are supported right now.
- RGB with 8 or 16 bits
- RGB + Alpha with 8 or 16 bits
- Grayscale with 8 or 16 bits
- Grayscale + Alpha with 8 or 16 bits
If you run into errors like
/usr/bin/ld: cannot find -lz
collect2: error: ld returned 1 exit status
make sure zlib
is installed
(Installing zlib under ubuntu).
Thanks goes to these wonderful people (emoji key):
Chris Hobbs π» |
Ary Borenszweig π» |
Alex Muscar π» |
Dru Jensen π» |
kojix2 π |
obskyr π» |
r00ster π» |
---|
This project follows the all-contributors specification. Contributions of any kind welcome!