From 7052cee8fb7005eb88138dd0e4099c2d299cf193 Mon Sep 17 00:00:00 2001 From: Paulo Castellano Date: Wed, 17 Jun 2026 20:24:44 -0300 Subject: [PATCH] fix(tweet-card): vertically center the name + handle block against the avatar --- app/Services/Image/TemplateImageGenerator.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/app/Services/Image/TemplateImageGenerator.php b/app/Services/Image/TemplateImageGenerator.php index 5f5a2a23..64fc1193 100644 --- a/app/Services/Image/TemplateImageGenerator.php +++ b/app/Services/Image/TemplateImageGenerator.php @@ -747,13 +747,21 @@ private function drawTweetCardContent(ImageInterface $canvas, mixed $core, Socia } $nameX = $avatarX + $avatarSize + 16; - $nameY = $avatarY + 11; $displayNameText = $socialAccount->display_name ?? ''; + $handleText = '@'.($socialAccount->username ?? ''); $nameBox = $fontBold ? imagettfbbox($nameSize, 0, $fontBold, $displayNameText) : [0, 0, 0, 0, 0, 0, 0, 0]; + $handleBox = $fontLight ? imagettfbbox($handleSize, 0, $fontLight, $handleText) : [0, 0, 0, 0, 0, 0, 0, 0]; $nameWidth = abs($nameBox[2] - $nameBox[0]); $nameAscent = (int) round(abs($nameBox[7])); + $handleAscent = (int) round(abs($handleBox[7])); + + // Vertically center the two-line (name + handle) block against the avatar. + $handleSpacing = (int) round($nameSize * 1.4); + $blockHeight = $handleSpacing + $handleAscent; + $nameY = $avatarY + (int) round(($avatarSize - $blockHeight) / 2); $nameBaselineY = $nameY + $nameAscent; + $handleBaselineY = $nameY + $handleSpacing + $handleAscent; if ($fontBold && $displayNameText !== '') { $this->drawTextAt($core, $displayNameText, $fontBold, $nameSize, '#0f1419', $nameX, $nameBaselineY); @@ -779,12 +787,8 @@ private function drawTweetCardContent(ImageInterface $canvas, mixed $core, Socia } } - $handleText = '@'.($socialAccount->username ?? ''); - $handleBox = $fontLight ? imagettfbbox($handleSize, 0, $fontLight, $handleText) : [0, 0, 0, 0, 0, 0, 0, 0]; - $handleAscent = (int) round(abs($handleBox[7])); - $handleY = $nameY + (int) round($nameSize * 1.4); if ($fontLight && $socialAccount->username) { - $this->drawTextAt($core, $handleText, $fontLight, $handleSize, '#536471', $nameX, $handleY + $handleAscent); + $this->drawTextAt($core, $handleText, $fontLight, $handleSize, '#536471', $nameX, $handleBaselineY); } $bodyStartY = $cardY + $headerH + 8;