Skip to content

Instantly share code, notes, and snippets.

@barce
Last active May 4, 2018 21:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save barce/90c079ee3e49619cdbb6f04e3a903924 to your computer and use it in GitHub Desktop.
Save barce/90c079ee3e49619cdbb6f04e3a903924 to your computer and use it in GitHub Desktop.
Naively check is an image is a grayscale image (very slow)
#!/usr/bin/env ruby
require 'rubygems'
require 'rmagick'
def is_grayscale(file_name)
Magick::Image.read('trix_pushed_2_stops.jpg')[0].each_pixel do |pixel, col, row|
puts "Pixel at: #{col}x#{row}:\tR: #{pixel.red}, G: #{pixel.green}, B: #{pixel.blue}"
unless (pixel.red == pixel.green) && (pixel.green == pixel.blue)
return FALSE
end
end
return TRUE
end
result = is_grayscale('trix_pushed_2_stops.jpg')
if result == TRUE
puts "your file is grayscale"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment