From 9f7b7976741f02a4f9d3b66f72d19a75b8e063a3 Mon Sep 17 00:00:00 2001 From: Paulo Castellano Date: Wed, 17 Jun 2026 19:21:19 -0300 Subject: [PATCH] feat(tweet-card): tabler verified badge (svg source committed) + badge placement next to name --- app/Services/Image/TemplateImageGenerator.php | 40 ++++++++---------- public/images/ai-templates/verified.png | Bin 402 -> 1451 bytes public/images/ai-templates/verified.svg | 11 +++++ 3 files changed, 29 insertions(+), 22 deletions(-) create mode 100644 public/images/ai-templates/verified.svg diff --git a/app/Services/Image/TemplateImageGenerator.php b/app/Services/Image/TemplateImageGenerator.php index a4be6670..92915295 100644 --- a/app/Services/Image/TemplateImageGenerator.php +++ b/app/Services/Image/TemplateImageGenerator.php @@ -625,23 +625,21 @@ public function renderTweetCard(Workspace $workspace, SocialAccount $socialAccou $nameX = $avatarX + $avatarSize + 16; $nameY = $avatarY + 4; - if ($fontBold) { - $canvas->text($socialAccount->display_name ?? '', $nameX, $nameY, function (FontFactory $font) use ($fontBold, $nameSize) { - $font->filename($fontBold); - $font->size($nameSize); - $font->color('#0f1419'); - $font->align('left', 'top'); - }); + $displayNameText = $socialAccount->display_name ?? ''; + $nameBox = $fontBold ? imagettfbbox($nameSize, 0, $fontBold, $displayNameText) : [0, 0, 0, 0, 0, 0, 0, 0]; + $nameWidth = abs($nameBox[2] - $nameBox[0]); + $nameAscent = (int) round(abs($nameBox[7])); + $nameBaselineY = $nameY + $nameAscent; + + if ($fontBold && $displayNameText !== '') { + $this->drawTextAt($core, $displayNameText, $fontBold, $nameSize, '#0f1419', $nameX, $nameBaselineY); } $verifiedPath = public_path('images/ai-templates/verified.png'); - if ($fontBold && file_exists($verifiedPath)) { - $displayNameText = $socialAccount->display_name ?? ''; - $nameBox = $fontBold ? imagettfbbox($nameSize, 0, $fontBold, $displayNameText) : [0, 0, 0, 0, 0, 0, 0, 0]; - $nameWidth = abs($nameBox[2] - $nameBox[0]); - $badgeSize = (int) round($nameSize * 1.1); - $badgeX = $nameX + $nameWidth + 6; - $badgeY = $nameY + (int) round(($nameSize - $badgeSize) / 2); + if ($fontBold && $displayNameText !== '' && file_exists($verifiedPath)) { + $badgeSize = (int) round($nameSize * 1.15); + $badgeX = $nameX + $nameWidth + 8; + $badgeY = $nameY + (int) round(($nameAscent - $badgeSize) / 2); $verifiedSrc = @imagecreatefrompng($verifiedPath); if ($verifiedSrc) { $verifiedResized = imagecreatetruecolor($badgeSize, $badgeSize); @@ -657,14 +655,12 @@ public function renderTweetCard(Workspace $workspace, SocialAccount $socialAccou } } - $handleY = $nameY + (int) round($nameSize * 1.35); - if ($fontLight) { - $canvas->text('@'.($socialAccount->username ?? ''), $nameX, $handleY, function (FontFactory $font) use ($fontLight, $handleSize) { - $font->filename($fontLight); - $font->size($handleSize); - $font->color('#536471'); - $font->align('left', 'top'); - }); + $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); } $bodyStartY = $cardY + $headerH + 8; diff --git a/public/images/ai-templates/verified.png b/public/images/ai-templates/verified.png index 2482d7138bc1789cb548fb6709f0a75491bfe2b4..3220b379f7a39659ba208e8c917e86dfb82558a0 100644 GIT binary patch literal 1451 zcmeAS@N?(olHy`uVBq!ia0vp^2_VeD3?#3*wSy!Sl0AZa85pY67#JE_7#My5g&JNk zFq9fFFuY1&V6d9Oz#v{QXIG#N0|R4WfKP}kP=W0152J`aApi_*Z=v_+fmCHlkY6wZ zgK*HqUC$5B4wE##e%qE&@PwGUwF6g74lln=+uMD`%u!zgM7B%0C;LcWsTB8J$P{1X zSi$Y7&!ffqfwSIlv0f=(u32bV`3HSesJuaCMWD8J)K zy(1AR_bR-bja^}7qlw~yWiP9(Hon{I2Xq8ulDE4HLkFv@2av;F;_2(k{)$adOu+bK z`0v?3A=MJsh?11Vl2ohYqEsNoU}RuqrfXoPYiJ%~WMpM%W@T!qZD3#pM7QrhL(!0% zpOTqYiCcqrTY3~wg9hA&lFZ!H;*!MN0^E9JCcCvVFfjFbx;Tbp+7-iG!C;`rMmcdHM0d$-hk}S9=<% z`=~n|IdVi|V#e)D`?e@yhqWi?#b*={ttlsvGoE>OC3|KvC3DX~9~YsaPDS(ET&{Xa|9 z^;S!w_2-&=@1FJPf#%ZsLxQ7w=_3EO^v3@VpUcaxmis64?Tian z`VX)1M_Ly6S(m)3*<_Uas-3&&!J@n;Jx><>O!VSA^UCelS+hm*&z>AmeUlm5`==n1 z@62nrYi3d>>mnvFhcB9caMt8^?W>Ct0Z~>kR87Oh@a(ABul}HmdKI;Vst0Ioo#NdN!< literal 402 zcmV;D0d4+?P)ZKPJN8p|CMmh7pgy??XK9V+yDRo07*qoM6N<$g0tVG;s5{u diff --git a/public/images/ai-templates/verified.svg b/public/images/ai-templates/verified.svg new file mode 100644 index 00000000..7d63fe7b --- /dev/null +++ b/public/images/ai-templates/verified.svg @@ -0,0 +1,11 @@ + + + + \ No newline at end of file