-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathavatar.php
42 lines (35 loc) · 1.25 KB
/
avatar.php
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
<?php
\OC_Log::write('saml', 'Returning image for '.$_REQUEST['user'], \OC_Log::WARN);
getAvatar($_REQUEST['user'], $_REQUEST['size']);
function getAvatar($user, $size) {
//\OC_JSON::checkLoggedIn();
//\OC_JSON::callCheck();
//\OC::$server->getSession()->close();
if ($size > 2048) {
$size = 2048;
}
// Undefined size
elseif ($size === 0) {
$size = 64;
}
$avatar = new \OC_Avatar($user);
$image = $avatar->get($size);
\OC_Response::disableCaching();
\OC_Response::setLastModifiedHeader(time());
if ($image instanceof \OC_Image) {
\OC_Response::setETagHeader(crc32($image->data()));
$image->show('image/png');
} else {
$img = imagecreate($size, $size); // 250
$hash = md5('color' . $user); // modify 'color' to get a different palette
imagecolorallocate($img, hexdec(substr($hash, 0, 2)),
hexdec(substr($hash, 2, 2)), hexdec(substr($hash, 4, 2)));
$textcolor = imagecolorallocate($img, 255, 255, 255);
$txt = strtoupper(substr($user, 0, 1));
$fontfile = \OC::$server->getRootFolder()->getFullPath("/")."/apps/chooser/FreeMonoBold.ttf";
//imagettftext($img, 100, 0, 85, 170, $textcolor , $fontfile, $txt);
imagettftext($img, 100*$size/200, 0, 76*$size/250, 170*$size/250, $textcolor , $fontfile, $txt);
imagepng($img);
}
}
?>