class Dhashion::Image
Public Class Methods
new(file)
click to toggle source
# File lib/dhashion.rb, line 8 def initialize(file) @image = Magick::Image.read(file).first rescue raise UnableToOpenImage, file end
Public Instance Methods
fingerprint()
click to toggle source
# File lib/dhashion.rb, line 14 def fingerprint x = @image.quantize(72, Magick::GRAYColorspace, Magick::NoDitherMethod, 8) .resize(9, 8, Magick::LagrangeFilter) .export_pixels(0, 0, 9, 8, 'I') x.map.with_index { |e, i| ((i != 0) && (e > x[i-1])) ? 1 : 0 } .join('') .to_i(2) end