Chunky Png Cheat Sheet

From WikiOD

Here is the cheatsheat of Chunky Png and basic guide on how to use Chunky Png

Loading[edit | edit source]

image = ChunkyPNG::Image.from_file('file.png')

Alternate ways[edit | edit source]

image = ChunkyPNG::Image.from_blob(File.read('file.png'))
image = ChunkyPNG::Image.from_io(io)

Loads from file.png.

Saving[edit | edit source]

image.save('filename.png')

Alternate ways[edit | edit source]

File.open('newfile.png', 'wb') { |io| image.write(io) }
binary_string = image.to_blob

Writes an image to newfile.png.

Drawing[edit | edit source]

image[0, 0] = ChunkyPNG::Color.rgba(255, 0,0, 128)
image.line(1, 1, 10, 1, ChunkyPNG::Color.from_hex('#aa007f'))

Canvas[edit | edit source]

crop(x, y, w, h)

Transforms[edit | edit source]

new_image = image.flip_horizontally.rotate_right

Credit:rstacruz