ruby_identicon 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +62 -0
- data/Rakefile +1 -0
- data/lib/ruby_identicon.rb +143 -0
- data/lib/ruby_identicon/version.rb +3 -0
- data/lib/siphash.rb +117 -0
- data/ruby_identicon.gemspec +39 -0
- data/spec/ruby_identicon_spec.rb +66 -0
- metadata +121 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 763a08551f9e59b52c16fd37d6f49a4818d1b474
|
4
|
+
data.tar.gz: ce13ad62ec04828f27d775eb59992e71eae6993c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ad4ac658f45c965c815849e5b04d4fa74fa9206524a276368aaff96b8013673b4e4588e3e3ba5cdcc79c9cc9e5c03b4e49cb7d67ca601549a1589c09b205372e
|
7
|
+
data.tar.gz: 8f5a5a5b9e7d6b70dfefa75367b3fed413270ea15fd9557891083e191cada9c45fd5d88a39b5c0a5709f843e1c7868764b2f2b4a2eadc56d1469abeb0439b0dd
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Chris Branson
|
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,62 @@
|
|
1
|
+
# RubyIdenticon
|
2
|
+
|
3
|
+
![Example Identicon](https://dl.dropboxusercontent.com/u/176278/ruby_identicon.png)
|
4
|
+
|
5
|
+
A Ruby implementation of [go-identicon](https://github.com/dgryski/go-identicon) by Damian Gryski
|
6
|
+
|
7
|
+
RubyIdenticon creates an [identicon](https://en.wikipedia.org/wiki/Identicon), similar to those created by [Github](https://github.com/blog/1586-identicons).
|
8
|
+
|
9
|
+
A title and key are used by siphash to calculate a hash value that is then used to create a visual identicon representation. The identicon is made by creating a left hand side pixel representation of each bit in the hash value - this is then mirrored onto the right hand side to create an image that we see as a shape. The grid and square sizes can be varied to create identicons of differing size.
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
gem 'ruby_identicon'
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install ruby_identicon
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
Creating an identicon and saving to png
|
28
|
+
|
29
|
+
RubyIdenticon.create_and_save("RubyIdenticon", "ruby_identicon.png")
|
30
|
+
|
31
|
+
Creating an identicon and returning a binary string
|
32
|
+
|
33
|
+
blob = RubyIdenticon.create("RubyIdenticon")
|
34
|
+
|
35
|
+
# optional, save to a file
|
36
|
+
File.open("ruby_identicon.png", "wb") do |f| f.write(blob) end
|
37
|
+
|
38
|
+
## Customising the identicon
|
39
|
+
|
40
|
+
The identicon can be customised by passing additional options
|
41
|
+
|
42
|
+
background_color: (Integer, default 0) the background color of the identicon in rgba notation (e.g. xffffffff for white)
|
43
|
+
border_size: (Integer, default 35) the size in pixels to leave as an empty border around the identicon image
|
44
|
+
grid_size: (Integer, default 7) the number of rows and columns in the identicon, minimum 4, maximum 9
|
45
|
+
square_size: (Integer, default 50) the size in pixels of each square that makes up the identicon
|
46
|
+
key: (String) a 16 byte key used by siphash when calculating the hash value (see note below)
|
47
|
+
|
48
|
+
Varying the key ensures uniqueness of an identicon for a given title, it is assumed desirable for different applications
|
49
|
+
to use a different key.
|
50
|
+
|
51
|
+
Example
|
52
|
+
|
53
|
+
blob = RubyIdenticon.create("identicons are great!", grid_size: 5, square_size: 70, background_color: 0xf0f0f0ff, key: "1234567890123456")
|
54
|
+
File.open("tmp/test_identicon.png", "wb") do |f| f.write(blob) end
|
55
|
+
|
56
|
+
## Contributing
|
57
|
+
|
58
|
+
1. Fork it
|
59
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
60
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
61
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
62
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,143 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2013 Chris Branson
|
3
|
+
#
|
4
|
+
# Based on the go-identicon code at https://github.com/dgryski/go-identicon
|
5
|
+
# go-identicon Copyright (c) 2013, Damian Gryski <damian@gryski.com>
|
6
|
+
# Credit to Damian Gryski for the original concept.
|
7
|
+
#
|
8
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
9
|
+
# a copy of this software and associated documentation files (the
|
10
|
+
# "Software"), to deal in the Software without restriction, including
|
11
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
12
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
13
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
14
|
+
# the following conditions:
|
15
|
+
#
|
16
|
+
# The above copyright notice and this permission notice shall be
|
17
|
+
# included in all copies or substantial portions of the Software.
|
18
|
+
#
|
19
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
20
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
21
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
22
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
23
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
24
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
25
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
26
|
+
#++
|
27
|
+
|
28
|
+
#
|
29
|
+
# A Ruby implementation of go-identicon
|
30
|
+
#
|
31
|
+
# RubyIdenticon creates an Identicon, similar to those created by Github.
|
32
|
+
#
|
33
|
+
# A title and key are used by siphash to calculate a hash value that is
|
34
|
+
# then used to create a visual identicon representation.
|
35
|
+
#
|
36
|
+
# The identicon is made by creating a left hand side pixel representation
|
37
|
+
# of each bit in the hash value - this is then mirrored onto the right
|
38
|
+
# hand side to create an image that we see as a shape.
|
39
|
+
#
|
40
|
+
# The grid and square sizes can be varied to create identicons of
|
41
|
+
# differing size.
|
42
|
+
#
|
43
|
+
|
44
|
+
require "ruby_identicon/version"
|
45
|
+
require "chunky_png"
|
46
|
+
require "siphash"
|
47
|
+
|
48
|
+
module RubyIdenticon
|
49
|
+
# the default paramters used when creating identicons
|
50
|
+
#
|
51
|
+
# background_color: (Integer, default 0) the background color of the identicon in rgba notation (e.g. xffffffff for white)
|
52
|
+
# border_size: (Integer, default 35) the size in pixels to leave as an empty border around the identicon image
|
53
|
+
# grid_size: (Integer, default 7) the number of rows and columns in the identicon, minimum 4, maximum 9
|
54
|
+
# square_size: (Integer, default 50) the size in pixels of each square that makes up the identicon
|
55
|
+
# key: (String) a 16 byte key used by siphash when calculating the hash value (see note below)
|
56
|
+
#
|
57
|
+
# varying the key ensures uniqueness of an identicon for a given title, it is assumed desirable for different applications
|
58
|
+
# to use a different key.
|
59
|
+
#
|
60
|
+
|
61
|
+
DEFAULT_PARAMETERS = {
|
62
|
+
border_size: 35,
|
63
|
+
square_size: 50,
|
64
|
+
grid_size: 7,
|
65
|
+
background_color: ChunkyPNG::Color::TRANSPARENT,
|
66
|
+
key: "\x00\x11\x22\x33\x44\x55\x66\x77\x88\x99\xAA\xBB\xCC\xDD\xEE\xFF"
|
67
|
+
}
|
68
|
+
|
69
|
+
# create an identicon png and save it to the given filename
|
70
|
+
#
|
71
|
+
# Example:
|
72
|
+
# >> RubyIdenticon.create_and_save("identicons are great!", "test_identicon.png")
|
73
|
+
# => result (Boolean)
|
74
|
+
#
|
75
|
+
# Arguments:
|
76
|
+
# title: (String)
|
77
|
+
# filename: (String)
|
78
|
+
# options: (Hash)
|
79
|
+
|
80
|
+
def self.create_and_save(title, filename, options = {})
|
81
|
+
raise "filename cannot be nil" if filename == nil
|
82
|
+
|
83
|
+
blob = create(title, options)
|
84
|
+
return false if blob == nil
|
85
|
+
|
86
|
+
File.open(filename, "wb") do |f| f.write(blob) end
|
87
|
+
end
|
88
|
+
|
89
|
+
# create an identicon png and return it as a binary string
|
90
|
+
#
|
91
|
+
# Example:
|
92
|
+
# >> RubyIdenticon.create("identicons are great!")
|
93
|
+
# => binary blob (String)
|
94
|
+
#
|
95
|
+
# Arguments:
|
96
|
+
# title: (String)
|
97
|
+
# options: (Hash)
|
98
|
+
|
99
|
+
def self.create(title, options = {})
|
100
|
+
options = DEFAULT_PARAMETERS.merge(options)
|
101
|
+
|
102
|
+
raise "title cannot be nil" if title == nil
|
103
|
+
raise "key is nil or less than 16 bytes" if options[:key] == nil || options[:key].length < 16
|
104
|
+
raise "grid_size must be between 4 and 9" if options[:grid_size] < 4 || options[:grid_size] > 9
|
105
|
+
raise "invalid border size" if options[:border_size] < 0
|
106
|
+
raise "invalid square size" if options[:square_size] < 0
|
107
|
+
|
108
|
+
hash = SipHash.digest(options[:key], title)
|
109
|
+
|
110
|
+
png = ChunkyPNG::Image.new((options[:border_size] * 2) + (options[:square_size] * options[:grid_size]),
|
111
|
+
(options[:border_size] * 2) + (options[:square_size] * options[:grid_size]), options[:background_color])
|
112
|
+
|
113
|
+
# set the foreground color by using the first three bytes of the hash value
|
114
|
+
color = ChunkyPNG::Color.rgba((hash & 0xff), ((hash >> 8) & 0xff), ((hash >> 16) & 0xff), 0xff)
|
115
|
+
|
116
|
+
# remove the first three bytes that were used for the foreground color
|
117
|
+
hash >>= 24
|
118
|
+
|
119
|
+
sqx = sqy = 0
|
120
|
+
for i in 0..(options[:grid_size] * ((options[:grid_size]+1) / 2))
|
121
|
+
if hash & 1 == 1
|
122
|
+
x = options[:border_size] + (sqx * options[:square_size])
|
123
|
+
y = options[:border_size] + (sqy * options[:square_size])
|
124
|
+
|
125
|
+
# left hand side
|
126
|
+
png.rect(x, y, x + options[:square_size], y + options[:square_size], color, color)
|
127
|
+
|
128
|
+
# mirror right hand side
|
129
|
+
x = options[:border_size] + ((options[:grid_size] - 1 - sqx) * options[:square_size])
|
130
|
+
png.rect(x, y, x + options[:square_size], y + options[:square_size], color, color)
|
131
|
+
end
|
132
|
+
|
133
|
+
hash >>= 1
|
134
|
+
sqy += 1
|
135
|
+
if sqy == options[:grid_size]
|
136
|
+
sqy = 0
|
137
|
+
sqx += 1
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
png.to_blob :color_mode => ChunkyPNG::COLOR_INDEXED
|
142
|
+
end
|
143
|
+
end
|
data/lib/siphash.rb
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2012 Martin Boßlet
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
# a copy of this software and associated documentation files (the
|
6
|
+
# "Software"), to deal in the Software without restriction, including
|
7
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
# the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be
|
13
|
+
# included in all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
#++
|
23
|
+
|
24
|
+
module SipHash
|
25
|
+
|
26
|
+
def self.digest(key, msg)
|
27
|
+
s = State.new(key)
|
28
|
+
len = msg.size
|
29
|
+
iter = len / 8
|
30
|
+
|
31
|
+
iter.times do |i|
|
32
|
+
m = msg.slice(i * 8, 8).unpack("Q<")[0]
|
33
|
+
s.apply_block(m)
|
34
|
+
end
|
35
|
+
|
36
|
+
m = last_block(msg, len, iter)
|
37
|
+
|
38
|
+
s.apply_block(m)
|
39
|
+
s.finalize
|
40
|
+
s.digest
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def self.last_block(msg, len, iter)
|
46
|
+
last = (len << 56) & State::MASK_64;
|
47
|
+
|
48
|
+
r = len % 8
|
49
|
+
off = iter * 8
|
50
|
+
|
51
|
+
last |= msg[off + 6].ord << 48 if r >= 7
|
52
|
+
last |= msg[off + 5].ord << 40 if r >= 6
|
53
|
+
last |= msg[off + 4].ord << 32 if r >= 5
|
54
|
+
last |= msg[off + 3].ord << 24 if r >= 4
|
55
|
+
last |= msg[off + 2].ord << 16 if r >= 3
|
56
|
+
last |= msg[off + 1].ord << 8 if r >= 2
|
57
|
+
last |= msg[off].ord if r >= 1
|
58
|
+
last
|
59
|
+
end
|
60
|
+
|
61
|
+
class State
|
62
|
+
|
63
|
+
MASK_64 = 0xffffffffffffffff
|
64
|
+
|
65
|
+
def initialize(key)
|
66
|
+
@v0 = 0x736f6d6570736575
|
67
|
+
@v1 = 0x646f72616e646f6d
|
68
|
+
@v2 = 0x6c7967656e657261
|
69
|
+
@v3 = 0x7465646279746573
|
70
|
+
|
71
|
+
k0 = key.slice(0, 8).unpack("Q<")[0]
|
72
|
+
k1 = key.slice(8, 8).unpack("Q<")[0]
|
73
|
+
|
74
|
+
@v0 ^= k0
|
75
|
+
@v1 ^= k1
|
76
|
+
@v2 ^= k0
|
77
|
+
@v3 ^= k1
|
78
|
+
end
|
79
|
+
|
80
|
+
def apply_block(m)
|
81
|
+
@v3 ^= m
|
82
|
+
2.times { compress }
|
83
|
+
@v0 ^= m
|
84
|
+
end
|
85
|
+
|
86
|
+
def rotl64(num, shift)
|
87
|
+
((num << shift) & MASK_64) | (num >> (64 - shift))
|
88
|
+
end
|
89
|
+
|
90
|
+
def compress
|
91
|
+
@v0 = (@v0 + @v1) & MASK_64
|
92
|
+
@v2 = (@v2 + @v3) & MASK_64
|
93
|
+
@v1 = rotl64(@v1, 13)
|
94
|
+
@v3 = rotl64(@v3, 16)
|
95
|
+
@v1 ^= @v0
|
96
|
+
@v3 ^= @v2
|
97
|
+
@v0 = rotl64(@v0, 32)
|
98
|
+
@v2 = (@v2 + @v1) & MASK_64
|
99
|
+
@v0 = (@v0 + @v3) & MASK_64
|
100
|
+
@v1 = rotl64(@v1, 17)
|
101
|
+
@v3 = rotl64(@v3, 21)
|
102
|
+
@v1 ^= @v2
|
103
|
+
@v3 ^= @v0
|
104
|
+
@v2 = rotl64(@v2, 32)
|
105
|
+
end
|
106
|
+
|
107
|
+
def finalize
|
108
|
+
@v2 ^= 0xff
|
109
|
+
4.times { compress }
|
110
|
+
end
|
111
|
+
|
112
|
+
def digest
|
113
|
+
@v0 ^ @v1 ^ @v2 ^ @v3
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|
117
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'ruby_identicon/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "ruby_identicon"
|
8
|
+
spec.version = RubyIdenticon::VERSION
|
9
|
+
spec.authors = ["Chris Branson"]
|
10
|
+
spec.email = ["branson.chris@gmail.com"]
|
11
|
+
|
12
|
+
spec.description = <<-EOT
|
13
|
+
A Ruby implementation of go-identicon by Damian Gryski
|
14
|
+
|
15
|
+
RubyIdenticon creates an identicon, similar to those created by Github.
|
16
|
+
|
17
|
+
A title and key are used by siphash to calculate a hash value that is then used
|
18
|
+
to create a visual identicon representation. The identicon is made by creating
|
19
|
+
a left hand side pixel representation of each bit in the hash value, this is then
|
20
|
+
mirrored onto the right hand side to create an image that we see as a shape.
|
21
|
+
|
22
|
+
The grid and square sizes can be varied to create identicons of differing size.
|
23
|
+
EOT
|
24
|
+
|
25
|
+
spec.summary = %q{A Ruby Gem for creating GitHub like identicons}
|
26
|
+
spec.homepage = ""
|
27
|
+
spec.license = "MIT"
|
28
|
+
|
29
|
+
spec.files = `git ls-files`.split($/)
|
30
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
31
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
32
|
+
spec.require_paths = ["lib"]
|
33
|
+
|
34
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
35
|
+
spec.add_development_dependency "rake"
|
36
|
+
spec.add_development_dependency "rspec", "~> 2.6"
|
37
|
+
|
38
|
+
spec.add_dependency "chunky_png", "~> 1.2.8"
|
39
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require 'ruby_identicon'
|
3
|
+
|
4
|
+
describe RubyIdenticon do
|
5
|
+
it "creates a binary string image blob" do
|
6
|
+
expect(RubyIdenticon.create("RubyIdenticon")).to be_a_kind_of(String)
|
7
|
+
end
|
8
|
+
|
9
|
+
it "does not create a binary string image blob with an invalid title" do
|
10
|
+
lambda { RubyIdenticon.create(nil) }.should raise_exception("title cannot be nil")
|
11
|
+
end
|
12
|
+
|
13
|
+
it "does not create a binary string image blob with an invalid key" do
|
14
|
+
lambda { RubyIdenticon.create("identicons are great!", key: "\x00\x11\x22\x33\x44") }.should raise_exception("key is nil or less than 16 bytes")
|
15
|
+
end
|
16
|
+
|
17
|
+
it "does not create a binary string image blob with an invalid grid size" do
|
18
|
+
lambda { RubyIdenticon.create("RubyIdenticon", grid_size: 2) }.should raise_exception("grid_size must be between 4 and 9")
|
19
|
+
lambda { RubyIdenticon.create("RubyIdenticon", grid_size: 20) }.should raise_exception("grid_size must be between 4 and 9")
|
20
|
+
end
|
21
|
+
|
22
|
+
it "does not create a binary string image blob with an invalid square_size size" do
|
23
|
+
lambda { RubyIdenticon.create("RubyIdenticon", square_size: -2) }.should raise_exception("invalid square size")
|
24
|
+
end
|
25
|
+
|
26
|
+
it "does not create a binary string image blob with an invalid border_size size" do
|
27
|
+
lambda { RubyIdenticon.create("RubyIdenticon", border_size: -2) }.should raise_exception("invalid border size")
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
|
32
|
+
it "creates a png image file" do
|
33
|
+
blob = RubyIdenticon.create("RubyIdenticon")
|
34
|
+
result = File.open("tmp/ruby_identicon.png", "wb") do |f| f.write(blob) end
|
35
|
+
expect(result).to be_true
|
36
|
+
end
|
37
|
+
|
38
|
+
it "creates a png image file of grid size 5, square size 70 and grey background" do
|
39
|
+
blob = RubyIdenticon.create("RubyIdenticon", grid_size: 5, square_size: 70, background_color: 0xf0f0f0ff, key: "1234567890123456")
|
40
|
+
result = File.open("tmp/ruby_identicon_gs5_white.png", "wb") do |f| f.write(blob) end
|
41
|
+
expect(result).to be_true
|
42
|
+
end
|
43
|
+
|
44
|
+
it "creates 10 png image files" do
|
45
|
+
10.times do |count|
|
46
|
+
blob = RubyIdenticon.create("RubyIdenticon_#{count}")
|
47
|
+
result = File.open("tmp/ruby_identicon_#{count}.png", "wb") do |f| f.write(blob) end
|
48
|
+
expect(result).to be_true
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
|
54
|
+
it "creates a png image file via create_and_save" do
|
55
|
+
result = RubyIdenticon.create_and_save("RubyIdenticon is fun", "tmp/test_identicon.png")
|
56
|
+
expect(result).to be_true
|
57
|
+
end
|
58
|
+
|
59
|
+
it "does not create a png image file via create_and_save with an invalid filename" do
|
60
|
+
lambda { RubyIdenticon.create_and_save("RubyIdenticon is fun", nil) }.should raise_exception("filename cannot be nil")
|
61
|
+
end
|
62
|
+
|
63
|
+
it "does not create a png image file via create_and_save with an invalid title" do
|
64
|
+
lambda { RubyIdenticon.create_and_save(nil, "tmp/test_identicon.png") }.should raise_exception("title cannot be nil")
|
65
|
+
end
|
66
|
+
end
|
metadata
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruby_identicon
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Chris Branson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-08-20 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: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.6'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.6'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: chunky_png
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.2.8
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.2.8
|
69
|
+
description: |2
|
70
|
+
A Ruby implementation of go-identicon by Damian Gryski
|
71
|
+
|
72
|
+
RubyIdenticon creates an identicon, similar to those created by Github.
|
73
|
+
|
74
|
+
A title and key are used by siphash to calculate a hash value that is then used
|
75
|
+
to create a visual identicon representation. The identicon is made by creating
|
76
|
+
a left hand side pixel representation of each bit in the hash value, this is then
|
77
|
+
mirrored onto the right hand side to create an image that we see as a shape.
|
78
|
+
|
79
|
+
The grid and square sizes can be varied to create identicons of differing size.
|
80
|
+
email:
|
81
|
+
- branson.chris@gmail.com
|
82
|
+
executables: []
|
83
|
+
extensions: []
|
84
|
+
extra_rdoc_files: []
|
85
|
+
files:
|
86
|
+
- .gitignore
|
87
|
+
- Gemfile
|
88
|
+
- LICENSE.txt
|
89
|
+
- README.md
|
90
|
+
- Rakefile
|
91
|
+
- lib/ruby_identicon.rb
|
92
|
+
- lib/ruby_identicon/version.rb
|
93
|
+
- lib/siphash.rb
|
94
|
+
- ruby_identicon.gemspec
|
95
|
+
- spec/ruby_identicon_spec.rb
|
96
|
+
homepage: ''
|
97
|
+
licenses:
|
98
|
+
- MIT
|
99
|
+
metadata: {}
|
100
|
+
post_install_message:
|
101
|
+
rdoc_options: []
|
102
|
+
require_paths:
|
103
|
+
- lib
|
104
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - '>='
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - '>='
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
requirements: []
|
115
|
+
rubyforge_project:
|
116
|
+
rubygems_version: 2.0.7
|
117
|
+
signing_key:
|
118
|
+
specification_version: 4
|
119
|
+
summary: A Ruby Gem for creating GitHub like identicons
|
120
|
+
test_files:
|
121
|
+
- spec/ruby_identicon_spec.rb
|