Skip to content

Instantly share code, notes, and snippets.

@mikeweber
Created June 27, 2011 17:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikeweber/1049324 to your computer and use it in GitHub Desktop.
Save mikeweber/1049324 to your computer and use it in GitHub Desktop.
Convert an image to a 10x10 pixelated version
require 'chunky_png'
image = ChunkyPNG::Image.from_file('input.png')
image.height.times do |y|
image.width.times do |x|
# As we iterate over each pixel, copy only the color of the pixel
# from the top left corner of this pixels 10x10 region
# e.g. the pixel at [69,17] will get set to the color from [60,10]
image[x, y] = image[x / 10 * 10, y / 10 * 10]
end
end
image.save('output.png')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment