daily pastebin goal
60%
SHARE
TWEET

Untitled

a guest Apr 14th, 2014 9,348 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top