Class: AverageHash::HashingStrategy
- Inherits:
-
Object
- Object
- AverageHash::HashingStrategy
- 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
- #generate_hash ⇒ Object
-
#initialize(file_path) ⇒ HashingStrategy
constructor
A new instance of HashingStrategy.
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_hash ⇒ Object
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 |