Drop the favicon generator script
CI / Deploy / PHP 8.4 (push) Successful in 1m11s
CI / Deploy / PHP 8.5 (push) Successful in 1m23s
CI / Deploy / test (push) Successful in 0s
CI / Deploy / deploy (push) Skipped

The logo is fixed, the generated files are all that is needed.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
gnilebeinandClaude Sonnet 5.5 committed 2026-11-16 14:05:04 +01:00
1 parent 82b352c053
commit 037a69c0ef
2 files changed
+3 -147

No files matched your search

+3 -3
View File
@@ -43,6 +43,6 @@ Neue Farben als Token in beiden Dark-Blöcken von `plenario.css` pflegen; auf de
Das Logo (`.brand__mark` in `plenario.css`) ist auch das Favicon: `webroot/favicon.svg` (moderne Browser), `favicon.ico` Das Logo (`.brand__mark` in `plenario.css`) ist auch das Favicon: `webroot/favicon.svg` (moderne Browser), `favicon.ico`
(16/32/48 px, Fallback) und `apple-touch-icon.png` (180 px, iOS, deckend ohne Rundung, die macht iOS selbst). Eingebunden über (16/32/48 px, Fallback) und `apple-touch-icon.png` (180 px, iOS, deckend ohne Rundung, die macht iOS selbst). Eingebunden über
`templates/element/favicon.php` in allen drei Layouts (default, present, error). Die Dateien sind statisch und werden aus `templates/element/favicon.php` in allen drei Layouts (default, present, error). Die Dateien sind statisch, es gibt keinen
einer Geometrie erzeugt: Ändert sich das Logo, `php resources/favicon/generate.php webroot` ausführen (braucht `ext-gd`) Generator im Repo: Das Logo ändert sich nicht. Falls doch, alle drei Dateien von Hand passend zu `.brand__mark` neu erstellen
und Farben/Anteile im Skript an `.brand__mark` angleichen. Test: `FaviconTest.php`. (Kreisdiagramm 40/25/20/15 % ab 12 Uhr im Uhrzeigersinn, Ecken 6/22). Test: `FaviconTest.php`.
-144
View File
@@ -1,144 +0,0 @@
<?php
// Generates webroot/favicon.svg, favicon.ico and apple-touch-icon.png (needs ext-gd). Run after a logo change:
// php resources/favicon/generate.php webroot
// Mirrors .brand__mark in webroot/css/plenario.css:
// rounded square (radius 6/22), conic gradient 40/25/20/15 % from 12 o'clock, clockwise.
declare(strict_types=1);
$out = rtrim($argv[1] ?? 'webroot', '/\\');
$colors = ['#4b3fe0', '#e0457b', '#12a08a', '#f29a1f'];
$stops = [0.40, 0.65, 0.85, 1.00];
$radiusRatio = 6 / 22;
// ---- SVG ---------------------------------------------------------------------------------
$size = 32;
$c = $size / 2;
$R = 24; // larger than the corner distance, the clip path trims it
$point = function (float $fraction) use ($c, $R): array {
$a = deg2rad($fraction * 360);
return [round($c + $R * sin($a), 3), round($c - $R * cos($a), 3)];
};
$paths = '';
$prev = 0.0;
foreach ($stops as $i => $stop) {
[$x1, $y1] = $point($prev);
[$x2, $y2] = $point($stop);
$large = ($stop - $prev) > 0.5 ? 1 : 0;
$paths .= sprintf(
" <path fill=\"%s\" d=\"M%d %d L%s %s A%d %d 0 %d 1 %s %s Z\"/>\n",
$colors[$i],
$c,
$c,
$x1,
$y1,
$R,
$R,
$large,
$x2,
$y2,
);
$prev = $stop;
}
$rx = round($size * $radiusRatio, 2);
$svg = <<<SVG
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 {$size} {$size}" width="{$size}" height="{$size}">
<title>PlenarIO</title>
<clipPath id="r"><rect width="{$size}" height="{$size}" rx="{$rx}"/></clipPath>
<g clip-path="url(#r)">
{$paths} </g>
</svg>
SVG;
file_put_contents($out . '/favicon.svg', $svg);
// ---- PNG / ICO (GD, 4x4 supersampling) ---------------------------------------------------
$rgb = fn(string $hex): array => [hexdec(substr($hex, 1, 2)), hexdec(substr($hex, 3, 2)), hexdec(substr($hex, 5, 2))];
$palette = array_map($rgb, $colors);
$render = function (int $n, float $padding = 0.0) use ($stops, $palette, $radiusRatio): string {
$img = imagecreatetruecolor($n, $n);
imagealphablending($img, false);
imagesavealpha($img, true);
$ss = 4;
$inner = $n * (1 - 2 * $padding);
$r = $inner * $radiusRatio;
$offset = $n * $padding;
for ($y = 0; $y < $n; $y++) {
for ($x = 0; $x < $n; $x++) {
$sum = [0.0, 0.0, 0.0];
$cover = 0;
for ($sy = 0; $sy < $ss; $sy++) {
for ($sx = 0; $sx < $ss; $sx++) {
$px = $x + ($sx + 0.5) / $ss - $offset;
$py = $y + ($sy + 0.5) / $ss - $offset;
if ($px < 0 || $py < 0 || $px > $inner || $py > $inner) {
continue;
}
// rounded corners
$cx = min(max($px, $r), $inner - $r);
$cy = min(max($py, $r), $inner - $r);
if (($px - $cx) ** 2 + ($py - $cy) ** 2 > $r ** 2) {
continue;
}
$angle = atan2($px - $inner / 2, -($py - $inner / 2)); // 0 = top, clockwise
$f = fmod($angle / (2 * M_PI) + 1, 1);
$k = 0;
while ($k < 3 && $f >= $stops[$k]) {
$k++;
}
foreach ($palette[$k] as $j => $v) {
$sum[$j] += $v;
}
$cover++;
}
}
$total = $ss * $ss;
if ($cover === 0) {
$col = imagecolorallocatealpha($img, 0, 0, 0, 127);
} else {
$col = imagecolorallocatealpha(
$img,
(int)round($sum[0] / $cover),
(int)round($sum[1] / $cover),
(int)round($sum[2] / $cover),
(int)round(127 * (1 - $cover / $total)),
);
}
imagesetpixel($img, $x, $y, $col);
}
}
ob_start();
imagepng($img, null, 9);
$png = (string)ob_get_clean();
return $png;
};
// favicon.ico with 16, 32 and 48 px (PNG compressed entries)
$sizes = [16, 32, 48];
$images = array_map(fn(int $n): string => $render($n), $sizes);
$ico = pack('vvv', 0, 1, count($sizes));
$offset = 6 + 16 * count($sizes);
foreach ($sizes as $i => $n) {
$ico .= pack('CCCCvvVV', $n, $n, 0, 0, 1, 32, strlen($images[$i]), $offset);
$offset += strlen($images[$i]);
}
file_put_contents($out . '/favicon.ico', $ico . implode('', $images));
// iOS ignores transparency (fills black) and rounds the corners itself: opaque full-bleed square.
$apple = imagecreatetruecolor(180, 180);
$stopsPx = $stops;
for ($y = 0; $y < 180; $y++) {
for ($x = 0; $x < 180; $x++) {
$angle = atan2($x + 0.5 - 90, -($y + 0.5 - 90));
$f = fmod($angle / (2 * M_PI) + 1, 1);
$k = 0;
while ($k < 3 && $f >= $stopsPx[$k]) {
$k++;
}
imagesetpixel($apple, $x, $y, imagecolorallocate($apple, ...$palette[$k]));
}
}
imagepng($apple, $out . '/apple-touch-icon.png', 9);
echo "ok\n";