Giter Club home page Giter Club logo

stumpy_png's Introduction

stumpy_png

Build Status

Documentation

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

Install the stumpy_png shard

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

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
endIf you get 

StumpyPNG.write(canvas, "rainbow.png")

PNG image with a color gradient

(See examples/ for more examples)

Reading PNG files

Color Types

  • Grayscale
  • Grayscale + Alpha
  • RGB
  • RGB + Alpha
  • Palette

Filter Types

  • None
  • Sub
  • Up
  • Average
  • Paeth

Interlacing Methods

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

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

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

stumpy_png's People

Contributors

l3kn avatar asterite avatar rx14 avatar drujensen avatar

Watchers

 avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.