Skip to content
Snippets Groups Projects
Commit 6f2fd384 authored by JediKev's avatar JediKev
Browse files

issue: Local Avatar Annotation

This addresses issue 4700 where local avatars where breaking queues with
Avatar Annotation. This is due to the local avatars not having a `setSize()`
function. This updates local avatars so that they can be resized.
parent eebef639
Branches
Tags
No related merge requests found
...@@ -23,7 +23,7 @@ require_once INCLUDE_DIR . 'class.avatar.php'; ...@@ -23,7 +23,7 @@ require_once INCLUDE_DIR . 'class.avatar.php';
try { try {
$ra = new RandomAvatar($_GET['mode']); $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::response(200, false, 'image/png', false);
Http::cacheable($_GET['uid'], false, 86400); Http::cacheable($_GET['uid'], false, 86400);
......
...@@ -107,12 +107,17 @@ class LocalAvatar ...@@ -107,12 +107,17 @@ class LocalAvatar
extends Avatar { extends Avatar {
var $mode; var $mode;
var $code; var $code;
var $size;
function __construct($user, $mode) { function __construct($user, $mode) {
parent::__construct($user); parent::__construct($user);
$this->mode = $mode; $this->mode = $mode;
} }
function setSize($size) {
$this->size = $size;
}
function getUrl($size) { function getUrl($size) {
$code = $this->code; $code = $this->code;
if (!$code && method_exists($this->user, 'getExtraAttr')) if (!$code && method_exists($this->user, 'getExtraAttr'))
...@@ -124,8 +129,12 @@ extends Avatar { ...@@ -124,8 +129,12 @@ extends Avatar {
// Generate a random string of 0-6 chars for the avatar signature // Generate a random string of 0-6 chars for the avatar signature
$uid = md5(strtolower($this->user->getEmail())); $uid = md5(strtolower($this->user->getEmail()));
return ROOT_PATH . 'avatar.php?'.Http::build_query(array('uid'=>$uid, $args = array('uid'=>$uid, 'mode' => $this->mode);
'mode' => $this->mode));
if ($this->size)
$args['size'] = $this->size;
return ROOT_PATH . 'avatar.php?' . Http::build_query($args);
} }
function toggle() { function toggle() {
...@@ -152,7 +161,7 @@ class RandomAvatar { ...@@ -152,7 +161,7 @@ class RandomAvatar {
$this->mode = $mode; $this->mode = $mode;
} }
function makeAvatar($uid) { function makeAvatar($uid, $size=null) {
$sprite = self::$sprites[$this->mode]; $sprite = self::$sprites[$this->mode];
if (!$sprite || !is_readable(ROOT_DIR . $sprite['file']) || !extension_loaded('gd')) if (!$sprite || !is_readable(ROOT_DIR . $sprite['file']) || !extension_loaded('gd'))
Http::redirect(ROOT_PATH.'images/mystery-oscar.png'); Http::redirect(ROOT_PATH.'images/mystery-oscar.png');
...@@ -172,6 +181,11 @@ class RandomAvatar { ...@@ -172,6 +181,11 @@ class RandomAvatar {
imagecopy($avatar, $source, 0, 0, $idx*$grid, $i*$grid, $grid, $grid); 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; return $avatar;
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment