-
Notifications
You must be signed in to change notification settings - Fork 129
/
demo.html
131 lines (125 loc) · 5.07 KB
/
demo.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<html>
<head>
<script src="pnglib.js"></script>
<script src="identicon.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<style>
img { image-rendering: pixelated; }
</style>
</head>
<body>
<div class="container-fluid">
<h1>Identicon.js</h1>
<div class="row">
<div class="col-md-12">
<h4>Basic Usage</h4>
<p>
Specify just a hash, use default background color, margins, and size.
<br> Note: SVGs will produce clearer images (see below). To make PNGs crisper, you can try adding the CSS rule <span style="font-family: fixed;">image-rendering: pixelated;</span>
</p>
<pre>
var hash = 'd6fe8c82fb0abac17a702fd2a94eff37';
var data = new Identicon(hash).toString();
document.write('<img src="data:image/png;base64,' + data + '">');</pre>
<script type="text/javascript">
hashes = [
{id: 'stewartlord', hash: 'd6fe8c82fb0abac17a702fd2a94eff37'},
{id: 'jasonlong', hash: '46384036044a604b6b3316fc167fc15f'},
{id: 'infusion', hash: '373ff2375be91ebc97501e67d24ccd4d'},
{id: 'ppuleo', hash: '001000101000000000000000099fff86'}
];
var i,
data;
for (i = 0; i < hashes.length; i++) {
data = new Identicon(hashes[i].hash).toString();
document.write(
hashes[i].id + '<br><img src="data:image/png;base64,' + data + '"><br><br>'
);
}
</script>
</div>
</div>
<div class="row">
<div class="col-md-12">
<h4>SVG Output</h4>
<p>To generate SVGs, set the 'format' option to 'svg'.</p>
<pre>
var hash = 'd6fe8c82fb0abac17a702fd2a94eff37';
var data = new Identicon(hash, {format: 'svg'}).toString();
document.write('<img src="data:image/svg+xml;base64,' + data + '">');</pre>
<script type="text/javascript">
hashes = [
{id: 'stewartlord', hash: 'd6fe8c82fb0abac17a702fd2a94eff37'},
{id: 'jasonlong', hash: '46384036044a604b6b3316fc167fc15f'},
{id: 'infusion', hash: '373ff2375be91ebc97501e67d24ccd4d'},
{id: 'ppuleo', hash: '001000101000000000000000099fff86'}
];
var i,
data;
for (i = 0; i < hashes.length; i++) {
data = new Identicon(hashes[i].hash, {format: 'svg'}).toString();
document.write(
hashes[i].id + '<br><img src="data:image/svg+xml;base64,' + data + '"><br><br>'
);
}
</script>
</div>
</div>
<div class="row">
<div class="col-md-12">
<h4>Options</h4>
<p>Specify a hash and an options object to customize background color, margins, size and format.</p>
<pre>
var hash = 'd6fe8c82fb0abac17a702fd2a94eff37';
var options = {
foreground: [255, 255, 255, 255],
background: [0, 0, 0, 255],
margin: 0.2,
size: 128,
format: 'svg'
};
var data = new Identicon(hash, options).toString();
document.write('<img src="data:image/svg+xml;base64,' + data + '">');</pre>
<script type="text/javascript">
var data;
hash = 'd6fe8c82fb0abac17a702fd2a94eff37',
options = {
foreground: [255, 255, 255, 255],
background: [0, 0, 0, 255],
margin: 0.2,
size: 128,
format: 'svg'
};
data = new Identicon(hash, options).toString();
document.write(
'<br><img src="data:image/svg+xml;base64,' + data + '"><br><br>'
);
</script>
</div>
</div>
<div class="row">
<div class="col-md-12">
<h4>Raw (Smaller)</h4>
<p>The toString() method accepts an optional boolean argument that when set to true will return unencoded image data which is slightly smaller than the default base64 output. In the case of SVG this is still safe to use in a data URI provided that the attribute is double-quoted.</p>
<pre>
var data = new Identicon(hash, options).toString(true);
document.write('<img src="data:image/svg+xml;utf8,' + data + '">');</pre>
<script type="text/javascript">
var data;
hash = 'd6fe8c82fb0abac17a702fd2a94eff37',
options = {
foreground: [255, 255, 255, 255],
background: [0, 0, 0, 255],
margin: 0.2,
size: 128,
format: 'svg'
};
// Raw argument set to true outputs raw xml
data = new Identicon(hash, options).toString(true);
document.write('<br><img src="data:image/svg+xml;utf8,' + data + '"><br><br>');
</script>
</div>
</div>
</div>
</body>
</html>