identicon 0.0.2 → 0.0.3
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.
- checksums.yaml +4 -4
- data/identicon.gemspec +8 -8
- data/lib/identicon.rb +84 -65
- metadata +11 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 089111120e3ecd928f381fb37796dc024b33a89e
|
4
|
+
data.tar.gz: 6e9af318764806f81014b5c03b2e287d07f3da0f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f3db94a2ec35df83d71ec3b8d62db038b63930d543a7b09cc098c6c0bf1ee1330cff26476c3ed81f217c9cc5024aa60513581f8cabf3b1b2540a4d43812bd465
|
7
|
+
data.tar.gz: 3c7885d97bcc5dbd30286564efff9d8d41149acfae6b4bdab33df44a4d2723fea37d65347c3b1559d36dc51efc002385cb1e9ed182302a7b5c0446a1cf5c64b7
|
data/identicon.gemspec
CHANGED
@@ -3,18 +3,18 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "identicon"
|
6
|
-
s.version = "0.0.
|
6
|
+
s.version = "0.0.3"
|
7
7
|
s.authors = ["Victor Gama"]
|
8
|
-
s.email = ["
|
8
|
+
s.email = ["hey@vito.io"]
|
9
9
|
|
10
10
|
s.description = "A simple github-like identicons generator."
|
11
|
-
s.summary
|
11
|
+
s.summary = "A simple github-like identicons generator."
|
12
12
|
s.homepage = "http://github.com/victorgama/identicon"
|
13
|
-
s.license
|
13
|
+
s.license = "MIT"
|
14
14
|
|
15
|
-
s.files
|
15
|
+
s.files = `git ls-files`.split($/)
|
16
16
|
s.executables = s.files.grep(%r{^bin/}) { |file| File.basename(file) }
|
17
|
-
s.require_paths
|
17
|
+
s.require_paths = ["lib"]
|
18
18
|
|
19
|
-
s.add_dependency "chunky_png"
|
20
|
-
end
|
19
|
+
s.add_dependency "chunky_png"
|
20
|
+
end
|
data/lib/identicon.rb
CHANGED
@@ -3,64 +3,72 @@ require 'chunky_png'
|
|
3
3
|
|
4
4
|
# Generates GitHub-like identicons using MD5 hashes
|
5
5
|
class Identicon
|
6
|
+
|
7
|
+
attr_accessor :size, :data, :background
|
8
|
+
|
9
|
+
CHARS_REGEX = /(\w)(\w)/
|
10
|
+
|
11
|
+
COLORS = {
|
12
|
+
:a => [196, 108, 168],
|
13
|
+
:b => [127, 219, 107],
|
14
|
+
:c => [83, 89, 215],
|
15
|
+
:d => [111, 198, 148],
|
16
|
+
:e => [186, 130, 82],
|
17
|
+
:f => [113, 66, 197],
|
18
|
+
:"0" => [201, 186, 84],
|
19
|
+
:"1" => [114, 153, 205],
|
20
|
+
:"2" => [141, 108, 204],
|
21
|
+
:"3" => [75, 183, 114],
|
22
|
+
:"4" => [192, 86, 82],
|
23
|
+
:"5" => [199, 115, 209],
|
24
|
+
:"6" => [206, 77, 94],
|
25
|
+
:"7" => [211, 135, 162],
|
26
|
+
:"8" => [71, 194, 197],
|
27
|
+
:"9" => [188, 110, 93]
|
28
|
+
}
|
29
|
+
|
6
30
|
class << self
|
7
31
|
# Generates a identicon using the data:image protocol.
|
8
32
|
# Usefull for web applications.
|
9
33
|
#
|
10
34
|
# === Parameters
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
|
35
|
+
# data - The data that will be converted to a identicon
|
36
|
+
# size - (Optional) The image size. Defaults to 420px
|
37
|
+
# background - (Optional) The background color to be used in a rgb array.
|
38
|
+
# Ex: [255, 255, 255]
|
15
39
|
def data_url_for(data, size = 420, background = nil)
|
16
|
-
img = self.new
|
40
|
+
img = self.new(data, size)
|
17
41
|
img.background = background unless background.nil?
|
18
42
|
img.generate_image
|
19
43
|
img.to_data_url
|
20
44
|
end
|
21
45
|
|
46
|
+
|
22
47
|
# Generates a identicon and stores it in a file
|
23
|
-
#
|
48
|
+
# Useful for web applications.
|
24
49
|
#
|
25
50
|
# === Parameters
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
51
|
+
# data - The data that will be converted to a identicon
|
52
|
+
# path - The path where the file will be stored
|
53
|
+
# size - (Optional) The image size. Defaults to 420px
|
54
|
+
# background - (Optional) The background color to be used in a rgb array.
|
55
|
+
# Ex: [255, 255, 255]
|
56
|
+
#
|
57
|
+
# Returns nothing
|
30
58
|
def file_for(data, path, size = 420, background = nil)
|
31
|
-
img = self.new
|
59
|
+
img = self.new(data, size)
|
32
60
|
img.background = background unless background.nil?
|
33
61
|
img.generate_image
|
34
62
|
img.save(path)
|
35
63
|
end
|
36
64
|
end
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
COLORS = {
|
41
|
-
:a => [196, 108, 168],
|
42
|
-
:b => [127, 219, 107],
|
43
|
-
:c => [83, 89, 215],
|
44
|
-
:d => [111, 198, 148],
|
45
|
-
:e => [186, 130, 82],
|
46
|
-
:f => [113, 66, 197],
|
47
|
-
:"0" => [201, 186, 84],
|
48
|
-
:"1" => [114, 153, 205],
|
49
|
-
:"2" => [141, 108, 204],
|
50
|
-
:"3" => [75, 183, 114],
|
51
|
-
:"4" => [192, 86, 82],
|
52
|
-
:"5" => [199, 115, 209],
|
53
|
-
:"6" => [206, 77, 94],
|
54
|
-
:"7" => [211, 135, 162],
|
55
|
-
:"8" => [71, 194, 197],
|
56
|
-
:"9" => [188, 110, 93]
|
57
|
-
}
|
58
|
-
|
59
|
-
# The +new+ method initializes a new Identicon instance
|
65
|
+
|
66
|
+
|
67
|
+
# Constructs a new Identicon instance
|
60
68
|
#
|
61
69
|
# === Parameters
|
62
|
-
#
|
63
|
-
#
|
70
|
+
# data - The data that will be converted to a identicon
|
71
|
+
# size - The image size
|
64
72
|
def initialize(data, size)
|
65
73
|
@hash = Digest::MD5.hexdigest(data.to_s)
|
66
74
|
@chars = @hash.scan(CHARS_REGEX)
|
@@ -80,6 +88,7 @@ class Identicon
|
|
80
88
|
value
|
81
89
|
end
|
82
90
|
|
91
|
+
|
83
92
|
def data=(value)
|
84
93
|
@hash = Digest::MD5.hexdigest(data.to_s)
|
85
94
|
@chars = @hash.scan(CHARS_REGEX)
|
@@ -87,6 +96,45 @@ class Identicon
|
|
87
96
|
value
|
88
97
|
end
|
89
98
|
|
99
|
+
|
100
|
+
# Process the specified data and generates the result
|
101
|
+
def generate_image
|
102
|
+
pImage = ChunkyPNG::Image.new(@image_size, @image_size, ChunkyPNG::Color::rgb(@background[0], @background[1], @background[2]))
|
103
|
+
@image = ChunkyPNG::Image.new(@size, @size, ChunkyPNG::Color::rgb(@background[0], @background[1], @background[2]))
|
104
|
+
@square_array.each_key { |lineKey|
|
105
|
+
lineValue = @square_array[lineKey]
|
106
|
+
lineValue.each_index { |colKey|
|
107
|
+
colValue = lineValue[colKey]
|
108
|
+
if(colValue)
|
109
|
+
pImage.rect(
|
110
|
+
colKey * @pixel_ratio,
|
111
|
+
lineKey * @pixel_ratio,
|
112
|
+
(colKey + 1) * @pixel_ratio,
|
113
|
+
(lineKey + 1) * @pixel_ratio,
|
114
|
+
ChunkyPNG::Color::TRANSPARENT,
|
115
|
+
ChunkyPNG::Color.rgb(@color[0], @color[1], @color[2])
|
116
|
+
)
|
117
|
+
end
|
118
|
+
}
|
119
|
+
}
|
120
|
+
@image.compose!(pImage, @pixel_ratio / 2, @pixel_ratio / 2)
|
121
|
+
end
|
122
|
+
|
123
|
+
|
124
|
+
# Exports the result to a data:image format.
|
125
|
+
def to_data_url
|
126
|
+
@image.to_data_url
|
127
|
+
end
|
128
|
+
|
129
|
+
|
130
|
+
# Exports the result to a file
|
131
|
+
# === Parameters
|
132
|
+
# path - Path where the image will be stored
|
133
|
+
def save(path)
|
134
|
+
@image.save(path)
|
135
|
+
end
|
136
|
+
|
137
|
+
|
90
138
|
private
|
91
139
|
def convert_hash
|
92
140
|
chars = @chars.map { |p|
|
@@ -115,33 +163,4 @@ class Identicon
|
|
115
163
|
def h_to_b(value)
|
116
164
|
value.bytes.first % 2 == 0
|
117
165
|
end
|
118
|
-
|
119
|
-
public
|
120
|
-
# Process the specified data and generates the result
|
121
|
-
def generate_image
|
122
|
-
pImage = ChunkyPNG::Image.new(@image_size, @image_size, ChunkyPNG::Color::rgb(@background[0], @background[1], @background[2]))
|
123
|
-
@image = ChunkyPNG::Image.new(@size, @size, ChunkyPNG::Color::rgb(@background[0], @background[1], @background[2]))
|
124
|
-
@square_array.each_key { |lineKey|
|
125
|
-
lineValue = @square_array[lineKey]
|
126
|
-
lineValue.each_index { |colKey|
|
127
|
-
colValue = lineValue[colKey]
|
128
|
-
if(colValue)
|
129
|
-
pImage.rect(colKey * @pixel_ratio, lineKey * @pixel_ratio, (colKey + 1) * @pixel_ratio, (lineKey + 1) * @pixel_ratio, ChunkyPNG::Color::TRANSPARENT, ChunkyPNG::Color.rgb(@color[0], @color[1], @color[2]))
|
130
|
-
end
|
131
|
-
}
|
132
|
-
}
|
133
|
-
@image.compose!(pImage, @pixel_ratio / 2, @pixel_ratio / 2)
|
134
|
-
end
|
135
|
-
|
136
|
-
# Exports the result to a data:image format.
|
137
|
-
def to_data_url
|
138
|
-
@image.to_data_url
|
139
|
-
end
|
140
|
-
|
141
|
-
# Exports the result to a file
|
142
|
-
# === Parameters
|
143
|
-
# * path = Path where the image will be stored
|
144
|
-
def save(path)
|
145
|
-
@image.save(path)
|
146
|
-
end
|
147
166
|
end
|
metadata
CHANGED
@@ -1,37 +1,37 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: identicon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Victor Gama
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-05-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: chunky_png
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: '0'
|
27
27
|
description: A simple github-like identicons generator.
|
28
28
|
email:
|
29
|
-
-
|
29
|
+
- hey@vito.io
|
30
30
|
executables: []
|
31
31
|
extensions: []
|
32
32
|
extra_rdoc_files: []
|
33
33
|
files:
|
34
|
-
- .gitignore
|
34
|
+
- ".gitignore"
|
35
35
|
- LICENSE
|
36
36
|
- README.md
|
37
37
|
- identicon.gemspec
|
@@ -46,17 +46,17 @@ require_paths:
|
|
46
46
|
- lib
|
47
47
|
required_ruby_version: !ruby/object:Gem::Requirement
|
48
48
|
requirements:
|
49
|
-
- -
|
49
|
+
- - ">="
|
50
50
|
- !ruby/object:Gem::Version
|
51
51
|
version: '0'
|
52
52
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
53
|
requirements:
|
54
|
-
- -
|
54
|
+
- - ">="
|
55
55
|
- !ruby/object:Gem::Version
|
56
56
|
version: '0'
|
57
57
|
requirements: []
|
58
58
|
rubyforge_project:
|
59
|
-
rubygems_version: 2.
|
59
|
+
rubygems_version: 2.2.2
|
60
60
|
signing_key:
|
61
61
|
specification_version: 4
|
62
62
|
summary: A simple github-like identicons generator.
|