Skip to content
Snippets Groups Projects
Unverified Commit eafb34d3 authored by Peter Rotich's avatar Peter Rotich Committed by GitHub
Browse files

Merge pull request #4721 from JediKev/issue/local-avatar-annotation

issue: Local Avatar Annotation
parents 4e5de6dc 6f2fd384
No related branches found
No related tags found
No related merge requests found
......@@ -23,7 +23,7 @@ require_once INCLUDE_DIR . 'class.avatar.php';
try {
$ra = new RandomAvatar($_GET['mode']);
$avatar = $ra->makeAvatar($_GET['uid']);
$avatar = $ra->makeAvatar($_GET['uid'], $_GET['size']);
Http::response(200, false, 'image/png', false);
Http::cacheable($_GET['uid'], false, 86400);
......
......@@ -107,12 +107,17 @@ class LocalAvatar
extends Avatar {
var $mode;
var $code;
var $size;
function __construct($user, $mode) {
parent::__construct($user);
$this->mode = $mode;
}
function setSize($size) {
$this->size = $size;
}
function getUrl($size) {
$code = $this->code;
if (!$code && method_exists($this->user, 'getExtraAttr'))
......@@ -124,8 +129,12 @@ extends Avatar {
// Generate a random string of 0-6 chars for the avatar signature
$uid = md5(strtolower($this->user->getEmail()));
return ROOT_PATH . 'avatar.php?'.Http::build_query(array('uid'=>$uid,
'mode' => $this->mode));
$args = array('uid'=>$uid, 'mode' => $this->mode);
if ($this->size)
$args['size'] = $this->size;
return ROOT_PATH . 'avatar.php?' . Http::build_query($args);
}
function toggle() {
......@@ -152,7 +161,7 @@ class RandomAvatar {
$this->mode = $mode;
}
function makeAvatar($uid) {
function makeAvatar($uid, $size=null) {
$sprite = self::$sprites[$this->mode];
if (!$sprite || !is_readable(ROOT_DIR . $sprite['file']) || !extension_loaded('gd'))
Http::redirect(ROOT_PATH.'images/mystery-oscar.png');
......@@ -172,6 +181,11 @@ class RandomAvatar {
imagecopy($avatar, $source, 0, 0, $idx*$grid, $i*$grid, $grid, $grid);
}
// Resize the avatar (if applicable)
if ($size) {
$avatar = imagescale($avatar, $size, $size);
}
return $avatar;
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment