Created
June 30, 2011 06:15
-
-
Save gberenfield/1055720 to your computer and use it in GitHub Desktop.
Pixelizing images with ChunkyPNG - codebrawl #2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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