pixavatar 0.0.0 → 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.
- checksums.yaml +4 -4
- data/lib/pixavatar.rb +78 -2
- metadata +21 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5a0174f3ccb4be7591e06897565394ca04641c38
|
4
|
+
data.tar.gz: 902414f411a2793b839194c8341371639eb3d0c4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dbe58aad9dc4b576acc3a579953e3bba548aa2554e50b2a96e2d3ef054915ea516664f795ad612b1b854e49cc12e15194a15c24f4fe0e5241479253483996374
|
7
|
+
data.tar.gz: c8494cde816f6d4958977f6a1d3b850e3312f3ef0a2c89096b8fc7dd4c873e4b447534d61969e6850606d63c8c7a871b41219a6475f6f7bed08d01a238364941
|
data/lib/pixavatar.rb
CHANGED
@@ -1,5 +1,81 @@
|
|
1
|
+
# stdlib
|
2
|
+
require "digest/md5"
|
3
|
+
|
4
|
+
# third party
|
5
|
+
require "chunky_png"
|
6
|
+
|
1
7
|
class Pixavatar
|
2
|
-
|
3
|
-
|
8
|
+
attr_accessor :avatar
|
9
|
+
|
10
|
+
def initialize(input_term)
|
11
|
+
@term = input_term
|
12
|
+
@term_hex = hashed_input
|
13
|
+
@avatar = {
|
14
|
+
color: get_color_code,
|
15
|
+
grid: pixel_grid_matrix
|
16
|
+
}
|
17
|
+
@colorable_grid = colorable_grid_map
|
4
18
|
end
|
19
|
+
|
20
|
+
def self.draw_image(input_term)
|
21
|
+
pixavatar_obj = self.new(input_term)
|
22
|
+
pixavatar_obj.draw_and_save_image
|
23
|
+
end
|
24
|
+
|
25
|
+
# draw image pattern in png file and export
|
26
|
+
def draw_and_save_image
|
27
|
+
color = @avatar[:color]
|
28
|
+
png = ChunkyPNG::Image.new(250, 250, ChunkyPNG::Color::WHITE)
|
29
|
+
color = ChunkyPNG::Color.rgba(color[:r], color[:g], color[:b], color[:alpha])
|
30
|
+
@colorable_grid.each do |points|
|
31
|
+
p1 = points[0]
|
32
|
+
p2 = points[1]
|
33
|
+
png.rect(p1[0], p1[1], p2[0], p2[1] , color, color)
|
34
|
+
end
|
35
|
+
png.save(File.join(Dir.pwd, "/#{@term}.png"), :interlace => true)
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
# convert input string to MD5 hex digest and return decimal array of the digest
|
41
|
+
def hashed_input
|
42
|
+
md5_hex = Digest::MD5.hexdigest(@term)
|
43
|
+
md5_hex.scan(/../).map { |s| s.to_i(16) }
|
44
|
+
end
|
45
|
+
|
46
|
+
# extract color code from the hex array
|
47
|
+
def get_color_code
|
48
|
+
{ r: @term_hex[0], g: @term_hex[1], b: @term_hex[2], alpha: @term_hex[-1] }
|
49
|
+
end
|
50
|
+
|
51
|
+
# generate mirrored 5x5 row from the generated @term_hex
|
52
|
+
def pixel_grid_matrix
|
53
|
+
tmp = []
|
54
|
+
@term_hex.slice(0,15).each_slice(3) do |row|
|
55
|
+
tmp << row + row.reverse.slice(1,2)
|
56
|
+
end
|
57
|
+
tmp.flatten
|
58
|
+
end
|
59
|
+
|
60
|
+
# filter colorable pixels from generated pixel grid
|
61
|
+
def colorable_grid_map(color_option = :even)
|
62
|
+
color_cordinates = []
|
63
|
+
pixel_grid = @avatar[:grid].map.with_index(0) do |num, i|
|
64
|
+
if num % 2 == 0
|
65
|
+
horizontal = (i % 5) * 50
|
66
|
+
vertical = (i / 5) * 50
|
67
|
+
|
68
|
+
top_left = [horizontal, vertical]
|
69
|
+
bottom_right = [horizontal + 50, vertical + 50]
|
70
|
+
[ top_left, bottom_right ]
|
71
|
+
end
|
72
|
+
end
|
73
|
+
pixel_grid.compact
|
74
|
+
end
|
75
|
+
|
76
|
+
|
5
77
|
end
|
78
|
+
|
79
|
+
Pixavatar.draw_image('sandeep')
|
80
|
+
|
81
|
+
|
metadata
CHANGED
@@ -1,16 +1,31 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pixavatar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
- Sandeep
|
7
|
+
- Sandeep
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
date: 2017-07-04 00:00:00.000000000 Z
|
12
|
-
dependencies:
|
13
|
-
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: chunky_png
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
description: Pixavatar is a simple placeholder image generator that can be used in
|
28
|
+
placeholder images where avatar images are missing
|
14
29
|
email: acharya_sandeep@hotmail.com
|
15
30
|
executables: []
|
16
31
|
extensions: []
|
@@ -37,8 +52,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
37
52
|
version: '0'
|
38
53
|
requirements: []
|
39
54
|
rubyforge_project:
|
40
|
-
rubygems_version: 2.6.
|
55
|
+
rubygems_version: 2.6.8
|
41
56
|
signing_key:
|
42
57
|
specification_version: 4
|
43
|
-
summary: generate unique pixel avatar
|
58
|
+
summary: generate unique pixel avatar image
|
44
59
|
test_files: []
|