Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Codebrawl #2 entry
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.