Module: DHashVips::DHash
Instance Method Summary collapse
- #calculate(file, hash_size = 8) ⇒ Object
- #hamming(a, b) ⇒ Object
- #pixelate(input, hash_size) ⇒ Object
Instance Method Details
#calculate(file, hash_size = 8) ⇒ Object
25 26 27 28 |
# File 'lib/dhash-vips.rb', line 25 def calculate file, hash_size = 8 image = pixelate file, hash_size image.cast("int").conv([[1, -1]]).crop(1, 0, hash_size, hash_size).>(0)./(255).cast("uchar").to_a.join.to_i(2) end |
#hamming(a, b) ⇒ Object
13 14 15 |
# File 'lib/dhash-vips.rb', line 13 def hamming a, b (a ^ b).to_s(2).count "1" end |
#pixelate(input, hash_size) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/dhash-vips.rb', line 17 def pixelate input, hash_size ::DHashVips.bw( if input.is_a? ::Vips::Image input.thumbnail_image(hash_size + 1, height: hash_size, size: :force) else ::Vips::Image.thumbnail(input, hash_size + 1, height: hash_size, size: :force) end ) end |