stumpy_png
Version, currently 5.0.113 versions
- 5.0.1latestMar 10, 2021
- 5.0.0not indexedDec 5, 2023
- 4.5.2not indexedDec 5, 2023
- 4.5.1not indexedDec 5, 2023
- 4.5.0not indexedDec 5, 2023
- 4.4.1not indexedDec 5, 2023
- 4.4.0not indexedDec 5, 2023
- 4.3.0not indexedDec 5, 2023
- 4.2.2not indexedDec 5, 2023
- 4.2.1not indexedDec 5, 2023
- 4.2.0not indexedDec 5, 2023
- 4.1.1not indexedDec 5, 2023
- 4.1.0not indexedDec 5, 2023
github.com/stumpycr/stumpy_png
Read/Write PNG images in pure Crystal
109 stars
55 dependents
License: MIT
Installation
# Add this to your shard.yml
dependencies:
stumpy_png:
github: stumpycr/stumpy_png
version: ~> 5.0.1Then run:
shards installshard.yml
- Crystal
0.35.1- License
- MIT
- Author
- Leon Rische
Dependencies
Runtime Dependencies
- stumpy_core~> 1.9github: stumpycr/stumpy_core
Development Dependencies
- minitest~> 0.5github: ysbaddaden/minitest.crdev
README
stumpy_png
Interface
StumpyPNG.read(path : String) : Canvasread a PNG image file from a pathStumpyPNG.read(io : IO) : Canvasread 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_depthis optional, valid values are8and16(default)color_typeis optional, valid values are:grayscale,:grayscale_alpha,:rgband:rgb_alpha(default)
StumpyPNG::PNG, helper class to store some state while parsing PNG filesCanvasandRGBAfrom stumpy_core
Usage
Install the stumpy_png shard
shards init- Add the dependency to the
shard.ymlfile
...
dependencies:
stumpy_png:
github: stumpycr/stumpy_png
version: "~> 5.0"
...
shards install
Reading
require "stumpy_png"
canvas = StumpyPNG.read("foo.png")
r, g, b = canvas[0, 0].to_rgb8
puts "red=#{r}, green=#{g}, blue=#{b}"
Writing
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)
Reading PNG files
Color Types
- [x] Grayscale
- [x] Grayscale + Alpha
- [x] RGB
- [x] RGB + Alpha
- [x] Palette
Filter Types
- [x] None
- [x] Sub
- [x] Up
- [x] Average
- [x] Paeth
Interlacing Methods
- [x] None
- [x] Adam7
Ancillary Chunks
None are supported right now.
Writing
- 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
Troubleshooting
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).
Contributors
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!
Documentation
Built from the current release. The first visit to a release nobody has asked for starts its build.
Links
This release
- Version
5.0.1- Tagged
- Mar 10, 2021
- Commit
7e1caa8ed2c6- Crystal
0.35.1- Indexed
- yes
Dependents
and 43 more
Repository
github.com/stumpycr/stumpy_png
Metadata
- Created
- Aug 12, 2026
- Updated
- Sep 23, 2026
- Synced
- Sep 23, 2026
- Versions
- 13