Files
amare/resources/views/components/media/image.blade.php
manoel freitas 321f0cee11 fix: restore lazy loading and CI visual baselines
Drop test-wide eager override that broke MediaImageComponentTest.
Replace local Chromium baselines with CI FrankenPHP host captures.
2026-08-06 09:50:48 -03:00

50 lines
1.6 KiB
PHP

@props([
'path',
'alt',
'sizes' => '(max-width: 768px) 100vw, 960px',
'loading' => 'lazy',
'fetchpriority' => null,
'width' => null,
'height' => null,
'disk' => null,
'class' => null,
])
@php
use App\Support\PublicImageUploadRules;
use App\Support\ResponsiveImage;
use Illuminate\Support\Facades\Storage;
$diskName = $disk ?? PublicImageUploadRules::disk();
$filesystem = Storage::disk($diskName);
$src = $filesystem->url($path);
$variants = ResponsiveImage::availableVariants($path, $diskName);
$srcset = collect($variants)
->map(fn (array $variant): string => $filesystem->url($variant['path']).' '.$variant['width'].'w')
->implode(', ');
if ($srcset === '' && $filesystem->exists($path)) {
$srcset = null;
}
$dimensions = ($width === null || $height === null)
? ResponsiveImage::dimensions($path, $diskName)
: null;
$resolvedWidth = $width ?? $dimensions['width'] ?? null;
$resolvedHeight = $height ?? $dimensions['height'] ?? null;
$loadingValue = $loading;
@endphp
<img
src="{{ $src }}"
@if ($srcset) srcset="{{ $srcset }}" sizes="{{ $sizes }}" @endif
alt="{{ $alt }}"
@if ($resolvedWidth) width="{{ $resolvedWidth }}" @endif
@if ($resolvedHeight) height="{{ $resolvedHeight }}" @endif
loading="{{ $loadingValue }}"
@if ($fetchpriority) fetchpriority="{{ $fetchpriority }}" @endif
@if ($class) class="{{ $class }}" @endif
{{ $attributes->except(['path', 'alt', 'sizes', 'loading', 'width', 'height', 'disk', 'class']) }}
>