Skip to content

Instantly share code, notes, and snippets.

@gberenfield
Created June 30, 2011 06:15
Show Gist options
  • Save gberenfield/1055720 to your computer and use it in GitHub Desktop.
Save gberenfield/1055720 to your computer and use it in GitHub Desktop.
Pixelizing images with ChunkyPNG - codebrawl #2
require 'rubygems'
require 'chunky_png'
module Pixelization
def pixelizing_replace!(size)
# This method uses the (0,0) color value for the (size,size) grid
# as the value throughout the pixelization
(0..self.height-1).step(size) do |h|
row = self.row(h)
indices = (0..width-size).step(size).to_a
indices.each do |i|
row[i,size] = size.times.map { row[i] }
end
size.times do |h_delta|
if (h + h_delta) < self.height
self.replace_row!(h + h_delta, row)
end
end
end
end
end
image = ChunkyPNG::Image.from_file('input.png')
image.extend Pixelization
image.pixelizing_replace!(10)
image.save("output.png")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment