Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Codebrawl #2 entry

View output.png
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
require 'chunky_png'
 
module ChunkyPNG
class Image
def pixelize!(size=10)
[[:row, height], [:column, width]].each do |orientation, length|
for i in 0...length
pixelated = []; send(orientation, i).each_slice(size) do |slice|
pixelated += [Color.rgba(*[:r,:g,:b,:a].map{|chan|
(slice.map{|c| Color.send(chan, c)}.inject(0.0){|sum, v| sum += v} / slice.length).round
})] * slice.length
end
send("replace_#{orientation}!", i, pixelated)
end
end
end
end
end
 
image = ChunkyPNG::Image.from_file('input.png')
image.pixelize!
image.save('output.png')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.