identiconify 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0ae4048275190d0183b3c2af76fe7e53b5179c0f
4
+ data.tar.gz: 9afeeff01281022b2cac056bb671e3ba15a78f4d
5
+ SHA512:
6
+ metadata.gz: d6e19538db2b8529837d03cbb47ecffa4f49113eb7dcf4bae4095d2cd959cc5458b0ceec1c5890ee0f120ed0ed264496af046311cb590b582af8822dd2f3f3a6
7
+ data.tar.gz: 68dad38abee7c6997c8b80283407ca5f38132fb1765a20b0bffe36aeca691ed08d92788d2b0658eccdfa1a2397bfbe9c0ebbb1ce653d2d83f1275da40f52ada3
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in identiconify.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Calle Erlandsson
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,48 @@
1
+ # Identiconify
2
+
3
+ Identiconify makes it super simple to generate identicons representing string
4
+ values such as usernames or ip addresses.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'identiconify'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install identiconify
19
+
20
+ ## Usage
21
+
22
+ Require the Identiconify
23
+
24
+ ```ruby
25
+ require 'identiconify'
26
+ ```
27
+
28
+ Now you have access to the Identiconify::Identicon class which can be use as
29
+ such:
30
+
31
+ ```ruby
32
+ string = "this is my string"
33
+ identicon = Identiconify::Identicon.new(string)
34
+ png_data = identicon.to_png_blob
35
+
36
+ # The png data can then be written to disk or be sent over an http connection
37
+ File.open('image.png', 'w') do |file|
38
+ file.write(png_data)
39
+ end
40
+ ```
41
+
42
+ ## Contributing
43
+
44
+ 1. Fork it
45
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
46
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
47
+ 4. Push to the branch (`git push origin my-new-feature`)
48
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'identiconify/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "identiconify"
8
+ spec.version = Identiconify::VERSION
9
+ spec.authors = ["calleerlandsson"]
10
+ spec.email = ["calle@omnidev.se"]
11
+ spec.description = "Identiconify makes it super simple to generate "\
12
+ "identicons representing string values such as "\
13
+ "usernames or ip addresses."
14
+ spec.summary = "Super simple identicons"
15
+ spec.homepage = "https://github.com/calleerlandsson/identiconify"
16
+ spec.license = "MIT"
17
+
18
+ spec.files = `git ls-files`.split($/)
19
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_runtime_dependency 'chunky_png', '~> 1.2', '>= 1.2.9'
26
+ spec.add_runtime_dependency 'siphash', '~> 0.0', '>= 0.0.1'
27
+ end
@@ -0,0 +1,3 @@
1
+ module Identiconify
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,60 @@
1
+ require "identiconify/version"
2
+ require "chunky_png"
3
+ require "siphash"
4
+
5
+ module Identiconify
6
+ class Identicon
7
+ HASH_KEY = "61616f73646a6173646a616f7369646a"
8
+
9
+ attr_reader :string, :square_size, :row_count
10
+
11
+ def initialize(string)
12
+ @string = string
13
+ @square_size = 50
14
+ @row_count = 5
15
+ end
16
+
17
+ def column_count
18
+ row_count.even? ? row_count/2 : row_count/2+1
19
+ end
20
+
21
+ def width
22
+ square_size * row_count
23
+ end
24
+
25
+ def to_png_blob
26
+ hash = SipHash.digest(HASH_KEY, string)
27
+
28
+ # Use the three first bytes of the hash to generate a color
29
+ r = hash & 0xff
30
+ g = (hash >> 8) & 0xff
31
+ b = (hash >> 16) & 0xff
32
+ a = 0xff
33
+ color = ChunkyPNG::Color.rgba(r,g,b,a)
34
+ bg_color = ChunkyPNG::Color::TRANSPARENT
35
+
36
+ # Remove the used three bytes
37
+ hash >>= 24
38
+
39
+ png = ChunkyPNG::Image.new(width, width, bg_color)
40
+ 0.upto(row_count).each do |row|
41
+ 0.upto(column_count).each do |column|
42
+ if hash & 1 == 1
43
+ x0 = column*square_size
44
+ y0 = row*square_size
45
+ x1 = (column+1)*square_size-1
46
+ y1 = (row+1)*square_size-1
47
+ png.rect(x0, y0, x1, y1, color, color)
48
+
49
+ # Inverse the x coordinates making the image mirrored vertically
50
+ x0 = width-(column+1)*square_size
51
+ x1 = width-column*square_size-1
52
+ png.rect(x0, y0, x1, y1, color, color)
53
+ end
54
+ hash >>= 1
55
+ end
56
+ end
57
+ png.to_blob :color_mode => ChunkyPNG::COLOR_INDEXED
58
+ end
59
+ end
60
+ end
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: identiconify
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - calleerlandsson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-11-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: chunky_png
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.2'
48
+ - - '>='
49
+ - !ruby/object:Gem::Version
50
+ version: 1.2.9
51
+ type: :runtime
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ~>
56
+ - !ruby/object:Gem::Version
57
+ version: '1.2'
58
+ - - '>='
59
+ - !ruby/object:Gem::Version
60
+ version: 1.2.9
61
+ - !ruby/object:Gem::Dependency
62
+ name: siphash
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ~>
66
+ - !ruby/object:Gem::Version
67
+ version: '0.0'
68
+ - - '>='
69
+ - !ruby/object:Gem::Version
70
+ version: 0.0.1
71
+ type: :runtime
72
+ prerelease: false
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: '0.0'
78
+ - - '>='
79
+ - !ruby/object:Gem::Version
80
+ version: 0.0.1
81
+ description: Identiconify makes it super simple to generate identicons representing
82
+ string values such as usernames or ip addresses.
83
+ email:
84
+ - calle@omnidev.se
85
+ executables: []
86
+ extensions: []
87
+ extra_rdoc_files: []
88
+ files:
89
+ - .gitignore
90
+ - Gemfile
91
+ - LICENSE.txt
92
+ - README.md
93
+ - Rakefile
94
+ - identiconify.gemspec
95
+ - lib/identiconify.rb
96
+ - lib/identiconify/version.rb
97
+ homepage: https://github.com/calleerlandsson/identiconify
98
+ licenses:
99
+ - MIT
100
+ metadata: {}
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - '>='
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ requirements: []
116
+ rubyforge_project:
117
+ rubygems_version: 2.0.6
118
+ signing_key:
119
+ specification_version: 4
120
+ summary: Super simple identicons
121
+ test_files: []