This commit is contained in:
@@ -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',
|
||||
|
||||
Reference in New Issue
Block a user