Created
June 27, 2011 17:26
-
-
Save mikeweber/1049324 to your computer and use it in GitHub Desktop.
Convert an image to a 10x10 pixelated version
This file contains hidden or 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' | |
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