stumpy_png

Read and write PNG images image-processing png
4.1.1 released
stumpycr/stumpy_png
103 20 2
stumpycr

stumpy_png

Build Status

Interface

  • StumpyPNG.read(path) : Canvas read a PNG image file
  • StumpyPNG.write(canvas, path, bit_depth: 16, color_type: :grayscale) saves a canvas as a PNG image file
    • bit_depth is optional, valid values are 8 and 16(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 files
  • Canvas and RGBA from stumpy_core

Usage

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

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

  • [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

  • [ ] tRNS
  • [ ] cHRM
  • [ ] gAMA
  • [ ] iCCP
  • [ ] sBIT
  • [ ] sRGB
  • [ ] tEXt
  • [ ] zTXt
  • [ ] iTXt
  • [ ] bKGD
  • [ ] hIST
  • [ ] pHYs
  • [ ] sPLT
  • [ ] tIME

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

Contributors

Thanks goes to these wonderful people (emoji key):

|
Chris Hobbs

|
Ary Borenszweig

|
Alex Muscar

| | :---: | :---: | :---: |

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

stumpy_png:
  github: stumpycr/stumpy_png
  version: ~> 4.1.1
License MIT
Crystal none

Authors

Dependencies 1

  • stumpy_core -> 1.0.0
    {'git' => 'https://github.com/l3kn/stumpy_core.git', 'version' => '-> 1.0.0'}

Development Dependencies 1

  • minitest ~> 0.3.5
    {'git' => 'https://github.com/ysbaddaden/minitest.cr.git', 'version' => '~> 0.3.5'}
Last synced .
search fire star recently