3, 'y1' => 0, 'x2' => 103, 'y2' => 40]; $BLAU = [0, 129, 199]; // #0081c7, das Logo-Blau $KANTE = 512; // Vorlage für alle Ableitungen des Kerns (16 bis 180) $RAND = 0.06; // wenig Luft: klein gelesen zählt jede Fläche $logo = imagecreatefrompng($quelle); $w = $AUSSCHNITT['x2'] - $AUSSCHNITT['x1'] + 1; $h = $AUSSCHNITT['y2'] - $AUSSCHNITT['y1'] + 1; $zeichen = imagecreatetruecolor($w, $h); imagealphablending($zeichen, false); imagesavealpha($zeichen, true); imagefilledrectangle($zeichen, 0, 0, $w, $h, imagecolorallocatealpha($zeichen, 0, 0, 0, 127)); for ($y = 0; $y < $h; ++$y) { for ($x = 0; $x < $w; ++$x) { // Das Logo ist ein Palettenbild; imagecolorsforindex beantwortet Palette und Truecolor. $c = imagecolorsforindex($logo, imagecolorat($logo, $AUSSCHNITT['x1'] + $x, $AUSSCHNITT['y1'] + $y)); $hell = $c['red'] > 230 && $c['green'] > 230 && $c['blue'] > 230; if ($c['alpha'] > 100 || $hell) { continue; } imagesetpixel($zeichen, $x, $y, imagecolorallocate($zeichen, 255, 255, 255)); } } imagedestroy($logo); $symbol = imagecreatetruecolor($KANTE, $KANTE); imagealphablending($symbol, false); imagesavealpha($symbol, true); imagefilledrectangle($symbol, 0, 0, $KANTE, $KANTE, imagecolorallocate($symbol, $BLAU[0], $BLAU[1], $BLAU[2])); imagealphablending($symbol, true); $platz = (int) round($KANTE * (1 - 2 * $RAND)); $faktor = min($platz / $w, $platz / $h); $zw = (int) round($w * $faktor); $zh = (int) round($h * $faktor); imagecopyresampled($symbol, $zeichen, (int) (($KANTE - $zw) / 2), (int) (($KANTE - $zh) / 2), 0, 0, $zw, $zh, $w, $h); imagedestroy($zeichen); $datei = sys_get_temp_dir().'/favicon-deeg.png'; imagepng($symbol, $datei, 9); imagedestroy($symbol); echo "Symbol gerendert: {$KANTE}x{$KANTE}\n"; $db = ConnectionFactory::create($url); $media = new MediaLibrary($db, str_replace('%kernel.project_dir%', $root, (string) $_SERVER['MEDIA_DIRECTORY'])); $settings = new SiteSettings($db, $media); $eintrag = $media->upload(new UploadedFile($datei, 'favicon-deeg.png', null, null, true)); $media->update($eintrag['id'], [ 'title' => 'Favicon DEEG', 'alt' => 'Dachgiebel aus dem DEEG-Logo, weiß auf Blau', 'archived' => false, 'version' => $eintrag['version'], ]); @unlink($datei); echo "In der Mediathek: {$eintrag['id']}\n"; $aktuell = $settings->load(); $settings->save([ ...$aktuell, // Gespeichert als Liste, erwartet als Textfeld - wie es der Einstellungsbildschirm schickt. 'sameAs' => implode("\n", $aktuell['sameAs']), 'faviconMediaId' => $eintrag['id'], ]); echo "Favicon gesetzt; der Kern hat 32 px (Browserleiste) und 180 px (Apple-Touch) daraus gerendert.\n";