-
-
Save jeffkreeftmeijer/1114072 to your computer and use it in GitHub Desktop.
codebrawl2
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' | |
include ChunkyPNG | |
# ten by ten pixles? | |
# might as well go 8 bit | |
# while we are at it | |
def reduce_depth(color, bits) | |
Color.rgb(*Color.to_truecolor_bytes(color). | |
map{ |c| c.to_f/256 }.each_with_index.map { |c,i| | |
(256.0 * (c*bits[i]).round / bits[i]).to_i | |
}) | |
end | |
def reduce_image(output, bits) | |
image = Image.from_file('input.png') | |
(0..image.width-1).step(10).each do |x| | |
(0..image.height-1).step(10).each do |y| | |
color = reduce_depth image[x,y], bits | |
10.times {|i| 10.times {|j| | |
image.set_pixel_if_within_bounds x+i, y+j, color | |
}} | |
end | |
end | |
image.save("#{output}.png") | |
end | |
reduce_image "8bit", [8,8,4] | |
reduce_image "4bit_r", [4,2,2] | |
reduce_image "4bit_g", [2,4,2] | |
reduce_image "4bit_b", [2,2,4] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment