70 lines
2.1 KiB
PHP
70 lines
2.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
/**
|
|
* Jednorazowy generator ikon PWA dla panelu kelnera.
|
|
* Uruchom: php scripts/generate_waiter_pwa_icons.php
|
|
*/
|
|
|
|
$outDir = __DIR__ . '/../public/waiter/icons';
|
|
if (!is_dir($outDir) && !mkdir($outDir, 0755, true) && !is_dir($outDir)) {
|
|
fwrite(STDERR, "Nie można utworzyć katalogu: {$outDir}\n");
|
|
exit(1);
|
|
}
|
|
|
|
function hexToRgb(string $hex): array
|
|
{
|
|
$hex = ltrim($hex, '#');
|
|
return [
|
|
(int) hexdec(substr($hex, 0, 2)),
|
|
(int) hexdec(substr($hex, 2, 2)),
|
|
(int) hexdec(substr($hex, 4, 2)),
|
|
];
|
|
}
|
|
|
|
function drawBell($img, int $size, float $scale, int $offsetY = 0): void
|
|
{
|
|
$cx = (int) ($size / 2);
|
|
$cy = (int) ($size / 2) + $offsetY;
|
|
$gold = imagecolorallocate($img, 245, 158, 11);
|
|
$goldLight = imagecolorallocate($img, 251, 191, 36);
|
|
$white = imagecolorallocate($img, 248, 250, 252);
|
|
|
|
$bellW = (int) ($size * 0.34 * $scale);
|
|
$bellH = (int) ($size * 0.36 * $scale);
|
|
$topY = $cy - (int) ($bellH * 0.55);
|
|
$bottomY = $cy + (int) ($bellH * 0.45);
|
|
|
|
imagefilledellipse($img, $cx, $topY + (int) ($bellH * 0.15), (int) ($bellW * 0.35), (int) ($bellH * 0.18), $gold);
|
|
imagefilledellipse($img, $cx, $topY + (int) ($bellH * 0.42), $bellW, $bellH, $goldLight);
|
|
imagefilledellipse($img, $cx, $bottomY, (int) ($bellW * 1.05), (int) ($bellH * 0.22), $gold);
|
|
imagefilledellipse($img, $cx, $bottomY + (int) ($bellH * 0.18), (int) ($bellW * 0.18), (int) ($bellH * 0.14), $white);
|
|
}
|
|
|
|
function renderIcon(int $size, bool $maskable): void
|
|
{
|
|
global $outDir;
|
|
|
|
$img = imagecreatetruecolor($size, $size);
|
|
imagesavealpha($img, true);
|
|
|
|
[$bgR, $bgG, $bgB] = hexToRgb('#0f172a');
|
|
$bg = imagecolorallocatealpha($img, $bgR, $bgG, $bgB, 0);
|
|
imagefill($img, 0, 0, $bg);
|
|
|
|
$scale = $maskable ? 0.62 : 0.78;
|
|
drawBell($img, $size, $scale);
|
|
|
|
$name = $maskable ? 'icon-maskable-512.png' : ($size === 192 ? 'icon-192.png' : 'icon-512.png');
|
|
$path = $outDir . DIRECTORY_SEPARATOR . $name;
|
|
imagepng($img, $path);
|
|
imagedestroy($img);
|
|
|
|
echo "Zapisano: {$path}\n";
|
|
}
|
|
|
|
renderIcon(192, false);
|
|
renderIcon(512, false);
|
|
renderIcon(512, true);
|