Use the logo as favicon #88
No files matched your search
@@ -38,3 +38,11 @@ Neue Farben als Token in beiden Dark-Blöcken von `plenario.css` pflegen; auf de
|
|||||||
Der Wake Lock ist standardmäßig an (braucht keine Nutzergeste); nur ein bewusstes Ausschalten wird gemerkt.
|
Der Wake Lock ist standardmäßig an (braucht keine Nutzergeste); nur ein bewusstes Ausschalten wird gemerkt.
|
||||||
Die Seite lädt bei Folienwechsel neu: der Wake Lock wird per `sessionStorage` (`plenario-wakelock`) wieder angefordert,
|
Die Seite lädt bei Folienwechsel neu: der Wake Lock wird per `sessionStorage` (`plenario-wakelock`) wieder angefordert,
|
||||||
Vollbild braucht eine Nutzergeste und muss nach dem Wechsel ggf. neu gewählt werden.
|
Vollbild braucht eine Nutzergeste und muss nach dem Wechsel ggf. neu gewählt werden.
|
||||||
|
|
||||||
|
## Favicon
|
||||||
|
|
||||||
|
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
|
||||||
|
`templates/element/favicon.php` in allen drei Layouts (default, present, error). Die Dateien sind statisch und werden aus
|
||||||
|
einer Geometrie erzeugt: Ändert sich das Logo, `php resources/favicon/generate.php webroot` ausführen (braucht `ext-gd`)
|
||||||
|
und Farben/Anteile im Skript an `.brand__mark` angleichen. Test: `FaviconTest.php`.
|
||||||
@@ -0,0 +1,144 @@
|
|||||||
|
<?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";
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Favicon links shared by all layouts. The SVG is the logo (same shape as .brand__mark in plenario.css) and wins
|
||||||
|
* wherever it is supported; favicon.ico is the fallback, apple-touch-icon.png is the iOS home screen icon.
|
||||||
|
*
|
||||||
|
* @var \App\View\AppView $this
|
||||||
|
*/
|
||||||
|
$asset = fn(string $file): string => $this->Url->assetUrl($file, ['pathPrefix' => '']);
|
||||||
|
?>
|
||||||
|
<link rel="icon" href="<?= h($asset('favicon.ico')) ?>" sizes="32x32">
|
||||||
|
<link rel="icon" href="<?= h($asset('favicon.svg')) ?>" type="image/svg+xml">
|
||||||
|
<link rel="apple-touch-icon" href="<?= h($asset('apple-touch-icon.png')) ?>">
|
||||||
@@ -17,7 +17,7 @@ $title = $this->fetch('title');
|
|||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
<title><?= $title ? h($title) . ' · ' : '' ?>PlenarIO</title>
|
<title><?= $title ? h($title) . ' · ' : '' ?>PlenarIO</title>
|
||||||
<?= $this->element('theme_init') ?>
|
<?= $this->element('theme_init') ?>
|
||||||
<?= $this->Html->meta('icon') ?>
|
<?= $this->element('favicon') ?>
|
||||||
<?= $this->Html->css(['normalize.min', 'plenario']) ?>
|
<?= $this->Html->css(['normalize.min', 'plenario']) ?>
|
||||||
<?= $this->fetch('meta') ?>
|
<?= $this->fetch('meta') ?>
|
||||||
<?= $this->fetch('css') ?>
|
<?= $this->fetch('css') ?>
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
<meta name="robots" content="noindex">
|
<meta name="robots" content="noindex">
|
||||||
<title><?= h($this->fetch('title')) ?> · PlenarIO</title>
|
<title><?= h($this->fetch('title')) ?> · PlenarIO</title>
|
||||||
<?= $this->element('theme_init') ?>
|
<?= $this->element('theme_init') ?>
|
||||||
<?= $this->Html->meta('icon') ?>
|
<?= $this->element('favicon') ?>
|
||||||
<?= $this->Html->css(['normalize.min', 'plenario']) ?>
|
<?= $this->Html->css(['normalize.min', 'plenario']) ?>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
<meta name="csrf-token" content="<?= h((string)$this->request->getAttribute('csrfToken')) ?>">
|
<meta name="csrf-token" content="<?= h((string)$this->request->getAttribute('csrfToken')) ?>">
|
||||||
<title><?= h($this->fetch('title')) ?> · PlenarIO</title>
|
<title><?= h($this->fetch('title')) ?> · PlenarIO</title>
|
||||||
<?= $this->element('theme_init', ['key' => 'plenario-theme-present', 'fallback' => 'dark']) ?>
|
<?= $this->element('theme_init', ['key' => 'plenario-theme-present', 'fallback' => 'dark']) ?>
|
||||||
<?= $this->Html->meta('icon') ?>
|
<?= $this->element('favicon') ?>
|
||||||
<?= $this->Html->css(['normalize.min', 'plenario']) ?>
|
<?= $this->Html->css(['normalize.min', 'plenario']) ?>
|
||||||
</head>
|
</head>
|
||||||
<body class="present">
|
<body class="present">
|
||||||
|
|||||||
@@ -0,0 +1,55 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Test\TestCase\Controller;
|
||||||
|
|
||||||
|
use App\Test\TestCase\PlenarioTestTrait;
|
||||||
|
use Cake\TestSuite\IntegrationTestTrait;
|
||||||
|
use Cake\TestSuite\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The logo as favicon: links in every layout and the files behind them.
|
||||||
|
*/
|
||||||
|
class FaviconTest extends TestCase
|
||||||
|
{
|
||||||
|
use IntegrationTestTrait;
|
||||||
|
use PlenarioTestTrait;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var list<string>
|
||||||
|
*/
|
||||||
|
protected array $fixtures = ['app.Polls', 'app.Slides', 'app.SlideOptions', 'app.Responses'];
|
||||||
|
|
||||||
|
public function testAllLayoutsLinkTheIcons(): void
|
||||||
|
{
|
||||||
|
[$poll, $token] = $this->createPoll();
|
||||||
|
$this->createSlide($poll);
|
||||||
|
|
||||||
|
// default, present and error layout
|
||||||
|
foreach (['/', '/admin/' . $token . '/present', '/does-not-exist'] as $url) {
|
||||||
|
$this->get($url);
|
||||||
|
// Root-relative, no "img/" prefix (static files live directly in webroot/).
|
||||||
|
$this->assertResponseRegExp('#<link rel="icon" href="/favicon\.svg(\?[^"]*)?" type="image/svg\+xml">#', $url);
|
||||||
|
$this->assertResponseRegExp('#<link rel="icon" href="/favicon\.ico(\?[^"]*)?" sizes="32x32">#', $url);
|
||||||
|
$this->assertResponseRegExp('#<link rel="apple-touch-icon" href="/apple-touch-icon\.png(\?[^"]*)?">#', $url);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testIconFilesAreValid(): void
|
||||||
|
{
|
||||||
|
$svg = (string)file_get_contents(WWW_ROOT . 'favicon.svg');
|
||||||
|
$this->assertStringContainsString('<svg', $svg);
|
||||||
|
$this->assertNotFalse(simplexml_load_string($svg), 'favicon.svg is not well-formed XML');
|
||||||
|
|
||||||
|
// ICO: reserved 0, type 1, three images; each entry's data starts with the PNG signature.
|
||||||
|
$ico = (string)file_get_contents(WWW_ROOT . 'favicon.ico');
|
||||||
|
$header = unpack('vreserved/vtype/vcount', $ico);
|
||||||
|
$this->assertSame([0, 1, 3], [$header['reserved'], $header['type'], $header['count']]);
|
||||||
|
for ($i = 0; $i < $header['count']; $i++) {
|
||||||
|
$entry = unpack('Voffset', $ico, 6 + 16 * $i + 12);
|
||||||
|
$this->assertSame("\x89PNG", substr($ico, $entry['offset'], 4));
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->assertSame([180, 180], array_slice(getimagesize(WWW_ROOT . 'apple-touch-icon.png'), 0, 2));
|
||||||
|
}
|
||||||
|
}
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 876 B |
Binary file not shown.
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 2.1 KiB |
@@ -0,0 +1,10 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32" width="32" height="32">
|
||||||
|
<title>PlenarIO</title>
|
||||||
|
<clipPath id="r"><rect width="32" height="32" rx="8.73"/></clipPath>
|
||||||
|
<g clip-path="url(#r)">
|
||||||
|
<path fill="#4b3fe0" d="M16 16 L16 -8 A24 24 0 0 1 30.107 35.416 Z"/>
|
||||||
|
<path fill="#e0457b" d="M16 16 L30.107 35.416 A24 24 0 0 1 -3.416 30.107 Z"/>
|
||||||
|
<path fill="#12a08a" d="M16 16 L-3.416 30.107 A24 24 0 0 1 -3.416 1.893 Z"/>
|
||||||
|
<path fill="#f29a1f" d="M16 16 L-3.416 1.893 A24 24 0 0 1 16 -8 Z"/>
|
||||||
|
</g>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 531 B |
Reference in new issue
Block a user