Skip to content

Instantly share code, notes, and snippets.

@ivanyv
Created July 1, 2011 22:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ivanyv/1059545 to your computer and use it in GitHub Desktop.
Save ivanyv/1059545 to your computer and use it in GitHub Desktop.
Make chunky pixels the brute force way
require 'rubygems'
require 'chunky_png'
orig = ChunkyPNG::Image.from_file('input.png')
rows = (orig.width / 10.0).ceil
cols = (orig.height / 10.0).ceil
canvas = ChunkyPNG::Canvas.new(rows * 10, cols * 10).replace(orig)
(0...rows).each do |row|
x = row * 10
(0...cols).each do |col|
y = col * 10
chunk = canvas.crop(x, y, 10, 10).resample(100, 100).crop(45, 45, 10, 10)
canvas.replace!(chunk, x, y)
end
end
canvas.crop(0, 0, orig.width, orig.height).save('output.png')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment