Skip to content

Instantly share code, notes, and snippets.

@Calamitous
Created June 28, 2011 19:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Calamitous/1051983 to your computer and use it in GitHub Desktop.
Save Calamitous/1051983 to your computer and use it in GitHub Desktop.
CodeBrawl entry for "Pixelizing images with ChunkyPNG"
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