ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilUserAvatarLetter.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
27{
32 protected static array $colors = [
33 "#0e6252", "#107360", "#aa890a", "#c87e0a", "#176437", "#196f3d", "#bf6516", "#a04000", "#1d6fa5", "#1b557a",
34 "#bf2718", "#81261d", "#713b87", "#522764", "#78848c", "#34495e", "#2c3e50", "#566566", "#90175a", "#9e2b6e",
35 "#d22f10", "#666d4e", "#715a32", "#83693a", "#963a30", "#e74c3c"
36 ];
37
38 public function getUrl(): string
39 {
40 static $amount_of_colors;
41 if (!isset($amount_of_colors)) {
42 $amount_of_colors = count(self::$colors);
43 }
44 // general idea, see https://gist.github.com/vctrfrnndz/fab6f839aaed0de566b0
45 $color = self::$colors[crc32($this->name) % $amount_of_colors];
46 $tpl = new \ilTemplate('tpl.letter_avatar.svg', true, true, 'components/ILIAS/User');
47 $tpl->setVariable('COLOR', $color);
48 $tpl->setVariable('SHORT', $this->name);
49
50 return 'data:image/svg+xml,' . rawurlencode($tpl->get());
51 }
52}
Class ilUserAvatarBase.
Class ilUserAvatarLetter.