dhashion 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/dhashion.rb +27 -0
  3. metadata +45 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 24f71d0f1bcb815072b430a62a8152d36e0c7a80
4
+ data.tar.gz: ae7a8346adedbe75623b392f2f392e43ed0599b1
5
+ SHA512:
6
+ metadata.gz: 4a3c4c48ddc989fd37a66a22af266e8b12b8b907fe0cf445c8d9e584fd82617354374fe8aae16944f2f88354dde18d5469c1b89ef5886769e10ca9bb05bc2b5b
7
+ data.tar.gz: 5b44a54cc6e8d02d0d2a22cc604af20e887f38c8822f81fb550642278ea98b9845b48a1d4c7ed2a923f9fcae0db0e94da3fbe815bea2203ecfbe5de619fd58b8
data/lib/dhashion.rb ADDED
@@ -0,0 +1,27 @@
1
+ # encoding: utf-8
2
+ require 'RMagick'
3
+
4
+ module Dhashion
5
+ UnableToOpenImage = Class.new(StandardError)
6
+
7
+ class Image
8
+ def initialize(file)
9
+ @image = Magick::Image.read(file).first
10
+ rescue
11
+ raise UnableToOpenImage, file
12
+ end
13
+
14
+ def fingerprint
15
+ x = @image.quantize(72, Magick::GRAYColorspace, Magick::NoDitherMethod, 8)
16
+ .resize(9, 8, Magick::LagrangeFilter)
17
+ .export_pixels(0, 0, 9, 8, 'I')
18
+ x.map.with_index { |e, i| ((i != 0) && (e > x[i-1])) ? 1 : 0 }
19
+ .join('')
20
+ .to_i(2)
21
+ end
22
+ end
23
+
24
+ def self.distance(x, y)
25
+ (x ^ y).to_s(2).count('1')
26
+ end
27
+ end
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dhashion
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Martin Manelli
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-15 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Lagrangian dHash in Ruby.
14
+ email: manelli.ml@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/dhashion.rb
20
+ homepage: http://github.com/manelli/dhashion
21
+ licenses:
22
+ - MIT
23
+ metadata: {}
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ requirements: []
39
+ rubyforge_project:
40
+ rubygems_version: 2.4.4
41
+ signing_key:
42
+ specification_version: 4
43
+ summary: dHash in Ruby.
44
+ test_files: []
45
+ has_rdoc: