✨ Story 3.6: optimisation images
This commit is contained in:
@@ -78,4 +78,33 @@ function getAllTechnologies(): array
|
||||
}
|
||||
sort($technologies);
|
||||
return $technologies;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper pour afficher une image projet optimisée
|
||||
*/
|
||||
function projectImage(string $filename, string $alt, int $width, int $height, bool $lazy = true): string
|
||||
{
|
||||
$webp = $filename;
|
||||
$fallback = str_replace('.webp', '.jpg', $filename);
|
||||
$lazyAttr = $lazy ? 'loading="lazy"' : '';
|
||||
|
||||
$altEsc = htmlspecialchars($alt, ENT_QUOTES, 'UTF-8');
|
||||
$webpEsc = htmlspecialchars($webp, ENT_QUOTES, 'UTF-8');
|
||||
$fallbackEsc = htmlspecialchars($fallback, ENT_QUOTES, 'UTF-8');
|
||||
|
||||
return <<<HTML
|
||||
<picture>
|
||||
<source srcset="/assets/img/projects/{$webpEsc}" type="image/webp">
|
||||
<img
|
||||
src="/assets/img/projects/{$fallbackEsc}"
|
||||
alt="{$altEsc}"
|
||||
width="{$width}"
|
||||
height="{$height}"
|
||||
{$lazyAttr}
|
||||
class="w-full h-full object-cover"
|
||||
onerror="this.onerror=null;this.src='/assets/img/projects/default-project.svg';"
|
||||
>
|
||||
</picture>
|
||||
HTML;
|
||||
}
|
||||
Reference in New Issue
Block a user