Class: AverageHash::HashingStrategy

Inherits:
Object
  • Object
show all
Defined in:
lib/average_hash/hashing_strategy.rb

Constant Summary collapse

RESIZNING_SIZE =
8
PIXEL_ACQUISITION_SIZE =
1
INDEX_OF_R =
0
INDEX_OF_G =
1
INDEX_OF_B =
2
NTSC_COEFFICIENT_OF_R =
0.30
NTSC_COEFFICIENT_OF_G =
0.59
NTSC_COEFFICIENT_OF_B =
0.11

Instance Method Summary collapse

Constructor Details

#initialize(file_path) ⇒ HashingStrategy

Returns a new instance of HashingStrategy.



18
19
20
# File 'lib/average_hash/hashing_strategy.rb', line 18

def initialize(file_path)
  @image = Magick::Image.read(file_path).first.resize(RESIZNING_SIZE, RESIZNING_SIZE)
end

Instance Method Details

#generate_hashObject



22
23
24
# File 'lib/average_hash/hashing_strategy.rb', line 22

def generate_hash
  (image_pixel_count.times).map { |i| gray_scaled_pixel(i) > average_pixel ? '1' : '0' }.join
end