Skip to content

Instantly share code, notes, and snippets.

@ucnv
Created March 10, 2013 08:20
Show Gist options
  • Save ucnv/5127611 to your computer and use it in GitHub Desktop.
Save ucnv/5127611 to your computer and use it in GitHub Desktop.
Glitch PNG with ChunkyPNG
require 'zlib'
require 'chunky_png'
p = ChunkyPNG::Datastream.from_file(ARGV.first)
a = p.data_chunks.inject('') { |b, c| b + c.content }
d = Zlib::Inflate.new().inflate(a)
d.gsub!(/0/, '1')
e = Zlib::Deflate.deflate(d)
p.data_chunks = [ChunkyPNG::Chunk::ImageData.new('IDAT', e)]
p.save('./out.png')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment