Last active
May 4, 2018 21:20
-
-
Save barce/90c079ee3e49619cdbb6f04e3a903924 to your computer and use it in GitHub Desktop.
Naively check is an image is a grayscale image (very slow)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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