31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/hash_avatar.rb', line 31
def self.gen(string='paolongtao')
hash = Digest::SHA1.hexdigest(string)
self.get_icons
@@avatar = Image.new(AVATAR_COLS, AVATAR_ROWS)
quarter = Image.new(QUARTER_COLS, QUARTER_ROWS)
hash_slice = []
for i in 0..5 do
hash_slice << hash.slice(i*4, 4)
end
icon_method_index = []
for i in 0..4 do
icon_method_index << Integer("0x#{hash_slice[i]}") % @@icon_method_size
end
icon_method_index << Integer("0x#{hash_slice[i]}") % Magick.colors.size
gc = Magick::Draw.new
gc.composite(0, 0, 0, 0, Icon.send(@@icon_method[icon_method_index[0]]))
gc.composite(ICON_COLS, 0, 0, 0, Icon.send(@@icon_method[icon_method_index[1]]))
gc.composite(0, ICON_ROWS, 0, 0, Icon.send(@@icon_method[icon_method_index[2]]))
gc.composite(ICON_COLS, ICON_ROWS, 0, 0, Icon.send(@@icon_method[icon_method_index[3]]))
gc.draw(quarter)
color = Magick.colors[icon_method_index[4]].name
quarter = quarter.opaque_channel(FrontColor, color, false, 10000, Magick::AllChannels)
gc.composite(0, 0, 0, 0, quarter)
gc.composite(QUARTER_COLS, 0, 0, 0, quarter.flop)
gc.composite(0, QUARTER_ROWS, 0, 0, quarter.flip)
gc.composite(QUARTER_COLS, QUARTER_ROWS, 0, 0, quarter.flop.flip)
gc.draw(@@avatar)
return @@avatar
end
|