Loheide-eu-mitarbeiterplatt.../app/Support/Theme/Icons.php
Friederich Loheide 82bbeef31b
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 2m7s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 2m11s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 2m16s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 2m18s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 2m49s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 2m46s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 2m41s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 2m33s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m0s
Phase 5: Erscheinungsbild mit Entwurf, Vorschau und Veröffentlichen
- Theme in den Einstellungen (Entwurf/veröffentlicht), Übernahme der
  Einstellungen aus Phase 0; statische CSS-Datei mit Hash beim Veröffentlichen
- Logos hell/dunkel, Signet, App-Symbol → Favicon, Homescreen-Symbole,
  Web-App-Manifest; SVG-Bereinigung
- Markenfarbe exakt, zweite Akzentfarbe, Kopfleiste hell/Marke/dunkel,
  Kontrastprüfung (WCAG AA) mit automatisch lesbarer Linkfarbe
- Lokale Schriften (Latein), Überschriften-Schrift, eigene WOFF2-Schrift,
  Ecken, Dichte, Dunkelmodus-Regel
- Anmeldeseite (geteilt/zentriert, Bild, Texte), Fußzeile, E-Mails im Design
- Admin: Live-Vorschau (Startseite, Anmeldung, Beispielseite; hell/dunkel),
  Veröffentlichen, Verwerfen, Export/Import, Zurücksetzen, eigenes CSS
- Admin-Bereich übernimmt Logo, Farbe und Favicon; Whitelabel

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-26 10:46:05 +00:00

66 lines
2.2 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace App\Support\Theme;
use App\Support\Images;
use Illuminate\Support\Facades\Storage;
use Intervention\Image\Drivers\Gd\Driver;
use Intervention\Image\Encoders\PngEncoder;
use Intervention\Image\ImageManager;
use Throwable;
/**
* Favicon und App-Symbole (Homescreen, Web-App) aus einem quadratischen Bild –
* in allen üblichen Größen. Ohne Bild: Monogramm in der Markenfarbe (SVG).
*/
class Icons
{
public const SIZES = [32, 180, 192, 512];
/**
* @param array<string, mixed> $theme
* @return array<int, string> Größe => Pfad im Speicher „uploads“
*/
public function generate(array $theme): array
{
$source = $theme['app_icon'] ?? null;
$disk = Storage::disk('uploads');
if (! $source || ! $disk->exists($source)) {
return [];
}
try {
Images::raiseMemoryLimitFor($disk->path($source));
$manager = ImageManager::usingDriver(Driver::class);
$hash = substr(sha1((string) $disk->get($source)), 0, 10);
$result = [];
foreach (self::SIZES as $size) {
$image = $manager->decodePath($disk->path($source));
$image->cover($size, $size);
$path = "theme/icons/icon-{$hash}-{$size}.png";
$disk->put($path, $image->encode(new PngEncoder)->toString());
$result[$size] = $path;
}
return $result;
} catch (Throwable $e) {
report($e);
return [];
}
}
/**
* Monogramm als SVG-Favicon (Daten-URL), wenn kein Symbol hochgeladen ist.
*/
public static function monogram(string $name, string $color, string $foreground): string
{
$letter = htmlspecialchars(mb_strtoupper(mb_substr(trim($name), 0, 1)) ?: 'P', ENT_XML1);
$svg = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64"><rect width="64" height="64" rx="14" fill="'.$color.'"/>'
.'<text x="32" y="44" font-family="Arial,Helvetica,sans-serif" font-size="34" font-weight="700" text-anchor="middle" fill="'.$foreground.'">'.$letter.'</text></svg>';
return 'data:image/svg+xml;base64,'.base64_encode($svg);
}
}