From 6f2fd38490c16d6b795f118b6ed0e26ff633f975 Mon Sep 17 00:00:00 2001 From: JediKev <kevin@enhancesoft.com> Date: Tue, 12 Feb 2019 10:54:51 -0600 Subject: [PATCH] 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. --- avatar.php | 2 +- include/class.avatar.php | 20 +++++++++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/avatar.php b/avatar.php index 77c0a7fbe..aafc6e48d 100644 --- a/avatar.php +++ b/avatar.php @@ -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); diff --git a/include/class.avatar.php b/include/class.avatar.php index ee55147fc..d49af12a1 100644 --- a/include/class.avatar.php +++ b/include/class.avatar.php @@ -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; } } -- GitLab