-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathidenticon.php
More file actions
34 lines (30 loc) · 773 Bytes
/
identicon.php
File metadata and controls
34 lines (30 loc) · 773 Bytes
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
<?php
#################################
# IMPLEMENTARE SIMPLA IDENTICON #
#################################
session_start();
function
get_identicon($text)
{
# Calculam hash-ul textului.
$hash = hash("sha3-512", $text);
# Culoarea este determinata de ultimii 3 octeti
$rgb = '#';
for ($k = 61; $k <= 63; ++$k) {
if (ord($hash[$k]) > 255)
$hash[$k] = chr(25);
$rgb .= dechex(ord($hash[$k]));
}
for ($i = 1; $i <= 10; ++$i)
for ($j = 1; $j <= 5; ++$j)
(int)$hash[$i*$j] & 1 ? $mat[$i][$j] = '██' : $mat[$i][$j] = '▒▒';
echo "<div class=\"iden\" style=\"color:$rgb;\">";
for ($i = 1; $i <= 10; ++$i) {
for ($j = 1; $j <= 5; ++$j)
echo $mat[$i][$j];
for ($j = 5; $j >= 1; --$j)
echo $mat[$i][$j];
echo "<br />";
}
echo "</div>";
}