Advertisement
Guest User

Untitled

a guest
Apr 14th, 2014
29,060
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.83 KB | None | 0 0
  1. #! /usr/bin/ruby
  2. require 'chunky_png'
  3.  
  4. image1 = ChunkyPNG::Image.from_file(ARGV[0])
  5. keyR = ARGV[1]
  6. keyG = ARGV[2]
  7. keyB = ARGV[3]
  8.  
  9. def go(r,g,b,image)
  10.     range=2
  11.     if r.to_i>255 or r.to_i<0 or g.to_i>255 or g.to_i<0 or b.to_i>255 or b.to_i<0
  12.         puts "Invalid arguments. Syntax is ./findColorin [IMAGE] [R VALUE] [G VALUE] [B VALUE]"
  13.         return 0
  14.     end
  15.     (0..image.dimension.width-1).each do |x|
  16.         (0..image.dimension.height-1).each do |y|
  17.             if (image[x,y] > ChunkyPNG::Color.rgb(r.to_i-range,g.to_i-range,b.to_i-range))and(image[x,y] < ChunkyPNG::Color.rgb(r.to_i+range,g.to_i+range,b.to_i+range))
  18.                 image[x,y] = ChunkyPNG::Color.rgb(0,0,0)
  19.             else
  20.                 image[x,y] = ChunkyPNG::Color.rgb(255,255,255)
  21.             end
  22.         end
  23.     end
  24.     puts "Saving to output.png"
  25.     image.save('output.png')
  26. end
  27.  
  28. go keyR, keyG, keyB, image1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement