Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! usr/bin/env ruby
- require 'chunky_png'
- class ChunkyPNG::Image
- # s: Integer (pixel size)
- def pixelize s = 10
- temp = Array.new((height*1.0/s).ceil) {Array.new((width*1.0/s).ceil) {Array.new(3) {0}}}
- height.times {|j| width.times {|i| ChunkyPNG::Color.to_truecolor_bytes(get_pixel(i,j)).each.with_index {|e,k| temp[j/s][i/s][k] += e}}}
- png = ChunkyPNG::Image.new width, height
- sq = s**2
- height.times {|j| width.times {|i| png.set_pixel(i,j, ChunkyPNG::Color.parse(ChunkyPNG::Color.rgb(*temp[j/s][i/s].map {|e| e/sq})))}}
- png
- end
- end
- image = ChunkyPNG::Image.from_file('input.png')
- image.pixelize.save('output_average.png')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement