avatar 2
All checks were successful
Deploy / deploy (push) Successful in 1m43s

This commit is contained in:
2026-07-27 01:50:38 +02:00
parent 08fffd24b6
commit 32985d5785
9 changed files with 216 additions and 79 deletions

View File

@@ -3,6 +3,7 @@ declare(strict_types=1);
use App\Avatar\Lorelei;
$allowedParams = ['eyesVariant', 'eyebrowsVariant', 'mouthVariant', 'glassesVariant', 'hairVariant', 'beardVariant', 'earringsVariant'];
$seed = Lorelei::normalizeSeed((string)($_GET['seed'] ?? 'papa-kind-treff'));
$cacheDir = dirname(__DIR__, 3) . '/assets/avatars/dicebear-cache';
@@ -10,11 +11,20 @@ if (!is_dir($cacheDir)) {
@mkdir($cacheDir, 0775, true);
}
$cacheFile = $cacheDir . '/' . $seed . '.svg';
$query = ['seed' => $seed, 'size' => '256'];
foreach ($allowedParams as $param) {
$value = Lorelei::normalizeVariant((string)($_GET[$param] ?? ''));
if ($value !== '') {
$query[$param] = $value;
}
}
$cacheKey = sha1(json_encode($query, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) ?: $seed);
$cacheFile = $cacheDir . '/' . $cacheKey . '.svg';
$svg = is_file($cacheFile) ? file_get_contents($cacheFile) : false;
if ($svg === false) {
$url = 'https://api.dicebear.com/10.x/lorelei/svg?seed=' . rawurlencode($seed) . '&size=256';
$url = 'https://api.dicebear.com/10.x/lorelei/svg?' . http_build_query($query);
$context = stream_context_create([
'http' => [
'method' => 'GET',