Advertisement
Guest User

Untitled

a guest
Aug 31st, 2015
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. #! usr/bin/env ruby
  2. require 'chunky_png'
  3.  
  4. class ChunkyPNG::Image
  5. # s: Integer (pixel size)
  6. def pixelize s = 10
  7. temp = Array.new((height*1.0/s).ceil) {Array.new((width*1.0/s).ceil) {Array.new(3) {0}}}
  8. 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}}}
  9. png = ChunkyPNG::Image.new width, height
  10. sq = s**2
  11. 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})))}}
  12. png
  13. end
  14. end
  15.  
  16. image = ChunkyPNG::Image.from_file('input.png')
  17. image.pixelize.save('output_average.png')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement