generated from boboko/starter
46 lines
1.6 KiB
PHP
46 lines
1.6 KiB
PHP
@props([
|
|
'src', // Stoic filename string e.g. "hero.png"
|
|
'preset' => 'medium', // which preset sets the src + default sizes hint
|
|
'alt' => '',
|
|
'loading' => 'lazy',
|
|
'fetchpriority' => 'auto',
|
|
'sizes' => null, // override when you know the render context
|
|
'width' => null,
|
|
'height' => null,
|
|
'preload' => false, // push a <link rel=preload> into <head> for LCP images
|
|
])
|
|
|
|
@php
|
|
$ext = strtolower(pathinfo($src, PATHINFO_EXTENSION));
|
|
$imageSrc = \App\Services\Stoic::image($src, $preset);
|
|
$srcset = \App\Services\Stoic::srcset($src);
|
|
$presetW = collect(\App\Services\Stoic::presets())->firstWhere('code', $preset)['width'] ?? 800;
|
|
$sizesAttr = $sizes ?? "(min-width: 1024px) {$presetW}px, 100vw";
|
|
[$width, $height] = $width !== null && $height !== null
|
|
? [$width, $height]
|
|
: \App\Services\Stoic::dimensions($src, $preset);
|
|
@endphp
|
|
|
|
@if($preload)
|
|
@push('seo')
|
|
<link rel="preload" as="image" href="{{ $imageSrc }}"
|
|
@if($srcset) imagesrcset="{{ $srcset }}" imagesizes="{{ $sizesAttr }}" @endif
|
|
@if($ext !== 'svg') type="image/webp" @endif
|
|
fetchpriority="high" />
|
|
@endpush
|
|
@endif
|
|
|
|
<img
|
|
src="{{ $imageSrc }}"
|
|
@if($srcset)
|
|
srcset="{{ $srcset }}"
|
|
sizes="{{ $sizesAttr }}"
|
|
@endif
|
|
@if($width !== null) width="{{ $width }}" @endif
|
|
@if($height !== null) height="{{ $height }}" @endif
|
|
alt="{{ $alt }}"
|
|
loading="{{ $loading }}"
|
|
fetchpriority="{{ $fetchpriority }}"
|
|
{{ $attributes }}
|
|
/>
|