From c1766b2abc82a21b578824fe24dc38b007163424 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6=20=28skjnldsv=29?= Date: Sat, 5 May 2018 18:19:42 +0200 Subject: [PATCH] Use base image size MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) --- lib/private/Avatar.php | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/lib/private/Avatar.php b/lib/private/Avatar.php index 07e8f2522c..2b0fb3d266 100644 --- a/lib/private/Avatar.php +++ b/lib/private/Avatar.php @@ -57,11 +57,18 @@ class Avatar implements IAvatar { private $logger; /** @var IConfig */ private $config; - /** @var string */ + + /** + * https://github.com/sebdesign/cap-height -- for 500px height + * Open Sans cap-height is 0.72 and we want a 200px caps height size (0.4 letter-to-total-height ratio, 500*0.4=200). 200/0.72 = 278px. + * Since we start from the baseline (text-anchor) we need to shift the y axis by 100px (half the caps height): 500/2+100=350 + * + * @var string + */ private $svgTemplate = ' - + - {letter} + {letter} '; /** @@ -265,13 +272,8 @@ class Avatar implements IAvatar { } /** - * https://github.com/sebdesign/cap-height -- for 500px height - * Open Sans cap-height is 0.72 and we want a 200px caps height size (0.4 letter-to-total-height ratio, 500*0.4=200). 200/0.72 = 278px. - * Since we start from the baseline (text-anchor) we need to shift the y axis by 100px (half the caps height): 500/2+100=350 --> * {size} = 500 * {fill} = hex color to fill - * {y} = top to bottom baseline text-anchor y position - * {font} = font size * {letter} = Letter to display * * Generate SVG avatar @@ -283,14 +285,10 @@ class Avatar implements IAvatar { $bgRGB = $this->avatarBackgroundColor($userDisplayName); $bgHEX = sprintf("%02x%02x%02x", $bgRGB->r, $bgRGB->g, $bgRGB->b); - $letter = mb_strtoupper(mb_substr($userDisplayName, 0, 1), 'UTF-8'); - $font = round($size * 0.4); - $fontSize = round($font / 0.72); - $y = round($size/2 + $font/2); - $toReplace = ['{size}', '{fill}', '{y}', '{font}', '{letter}']; - - return str_replace($toReplace, [$size, $bgHEX, $y, $fontSize, $letter], $this->svgTemplate); + + $toReplace = ['{size}', '{fill}', '{letter}']; + return str_replace($toReplace, [$size, $bgHEX, $letter], $this->svgTemplate); } /**