Created
June 28, 2011 19:33
-
-
Save Calamitous/1051983 to your computer and use it in GitHub Desktop.
CodeBrawl entry for "Pixelizing images with ChunkyPNG"
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 'chunky_png' | |
def pixellate(tile_size = 10) | |
tile_length = ((tile_size * tile_size) - 1) | |
image = ChunkyPNG::Image.from_file('input.png') | |
rework = image.resample_nearest_neighbor(image.width / tile_size, image.height / tile_size) | |
rework.height.times do |y| | |
rework.width.times do |x| | |
flat_pixel = rework[x, y] | |
(0..tile_length).each do |off| | |
image[(x * tile_size) + (off / tile_size), (y * tile_size) + (off % tile_size)] = flat_pixel | |
end | |
end | |
end | |
image.save('output.png') | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment