Home

Awesome

stumpy_png

CI

Documentation

Interface

Usage

Install the stumpy_png shard

  1. shards init
  2. Add the dependency to the shard.yml file
...
dependencies:
  stumpy_png:
    github: stumpycr/stumpy_png
    version: "~> 5.0"
...
  1. 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")

PNG image with a color gradient

(See examples/ for more examples)

Reading PNG files

Color Types

Filter Types

Interlacing Methods

Ancillary Chunks

None are supported right now.

Writing

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):

<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --> <!-- prettier-ignore -->
<img src="https://avatars.githubusercontent.com/u/2788811?v=3" width="100px;"/><br /><sub><b>Chris Hobbs</b></sub><br />💻<img src="https://avatars.githubusercontent.com/u/209371?v=3" width="100px;"/><br /><sub><b>Ary Borenszweig</b></sub><br />💻<img src="https://avatars.githubusercontent.com/u/90345?v=3" width="100px;"/><br /><sub><b>Alex Muscar</b></sub><br />💻<img src="https://avatars2.githubusercontent.com/u/18718?v=4" width="100px;"/><br /><sub><b>Dru Jensen</b></sub><br />💻<img src="https://avatars3.githubusercontent.com/u/5798442?v=4" width="100px;"/><br /><sub><b>kojix2</b></sub><br />📖<img src="https://avatars0.githubusercontent.com/u/4363779?v=4" width="100px;"/><br /><sub><b>obskyr</b></sub><br />💻<img src="https://avatars3.githubusercontent.com/u/35064754?v=4" width="100px;"/><br /><sub><b>r00ster</b></sub><br />💻
<!-- ALL-CONTRIBUTORS-LIST:END -->

This project follows the all-contributors specification. Contributions of any kind welcome!