Private
Public Access
1
0

chg: dev: remove the wrongly implemented font installation in docker - & replace it with static font on BattleCardGenerator (it solves the shareable image problem on bare-metal too) #8

This commit is contained in:
2026-04-21 14:18:59 +02:00
parent 8935216525
commit 085e010907
7 changed files with 66 additions and 21 deletions

View File

@@ -34,11 +34,11 @@ final class BattleCardGenerator
{
private const int WIDTH = 1200;
private const int HEIGHT = 630;
private const string FONT = '/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf';
private const int AVATAR_SIZE = 120;
public function __construct(
private readonly string $cacheDir,
private readonly string $fontPath,
private readonly FilesystemOperator $minioMediaStorage,
private readonly LoggerInterface $logger,
) {
@@ -159,7 +159,7 @@ final class BattleCardGenerator
$redBonusPoints = $game->redBonusPoints ?? 0;
$blueBonusPoints = $game->blueBonusPoints ?? 0;
$bonusText = number_format((float)$redBonusPoints, 1, '.', '') . ' * : * ' . number_format((float)$blueBonusPoints, 1, '.', '');
$this->centeredText($im, $bonusText, 24, self::WIDTH / 2, 425, $gold);
$this->centeredText($im, $bonusText, 24, self::WIDTH / 2, 445, $gold);
if ($winner === 'red') {
$resultText = $redName . ' wins';
@@ -176,11 +176,11 @@ final class BattleCardGenerator
}
if ($resultText !== '') {
$this->centeredText($im, $resultText, 30, self::WIDTH / 2, 475, $resultColor);
$this->centeredText($im, $resultText, 30, self::WIDTH / 2, 495, $resultColor);
}
if ($resign) {
$this->centeredText($im, ucfirst($resign) . ' resigned', 18, self::WIDTH / 2, 508, $muted);
$this->centeredText($im, ucfirst($resign) . ' resigned', 18, self::WIDTH / 2, 528, $muted);
}
$this->centeredText($im, 'mineseeker.hu', 16, self::WIDTH / 2, self::HEIGHT - 20, $muted);
@@ -273,23 +273,23 @@ final class BattleCardGenerator
/** Draw initials */
$initials = mb_strtoupper(mb_substr($name, 0, 2));
$fontSize = 48;
$bbox = imagettfbbox($fontSize, 0, self::FONT, $initials);
$bbox = imagettfbbox($fontSize, 0, $this->fontPath, $initials);
$textW = $bbox[2] - $bbox[0];
$textH = $bbox[1] - $bbox[7];
$textX = $cx - $textW / 2;
$textY = $cy + $textH / 2;
$white = imagecolorallocate($im, 255, 255, 255);
imagettftext($im, $fontSize, 0, (int)$textX, (int)$textY, $white, self::FONT, $initials);
imagettftext($im, $fontSize, 0, (int)$textX, (int)$textY, $white, $this->fontPath, $initials);
}
}
/** Render text centered on $cx. */
private function centeredText(GdImage $im, string $text, int $size, int $cx, int $y, int $color): void
{
$bbox = imagettfbbox($size, 0, self::FONT, $text);
$bbox = imagettfbbox($size, 0, $this->fontPath, $text);
$w = $bbox[2] - $bbox[0];
imagettftext($im, $size, 0, (int)($cx - $w / 2), $y, $color, self::FONT, $text);
imagettftext($im, $size, 0, (int)($cx - $w / 2), $y, $color, $this->fontPath, $text);
}
/** Render text centered on $cx, shrinking font size to fit $maxWidth. */
@@ -302,7 +302,7 @@ final class BattleCardGenerator
int $color,
int $maxWidth
): void {
$bbox = imagettfbbox($size, 0, self::FONT, $text);
$bbox = imagettfbbox($size, 0, $this->fontPath, $text);
$w = $bbox[2] - $bbox[0];
if ($w > $maxWidth) {
$size = (int)($size * $maxWidth / $w);