34 lines
776 B
PHP
34 lines
776 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\View\Components;
|
|
|
|
use Illuminate\Contracts\View\View;
|
|
use Illuminate\View\Component;
|
|
|
|
class WebPicture extends Component
|
|
{
|
|
public string $webpSrc;
|
|
|
|
public bool $hasWebp;
|
|
|
|
public function __construct(
|
|
public string $src,
|
|
public string $alt = '',
|
|
public string $class = '',
|
|
public string $loading = 'lazy',
|
|
public string $width = '',
|
|
public string $height = '',
|
|
) {
|
|
$this->webpSrc = preg_replace('/\.(jpe?g|png)$/i', '.webp', $this->src);
|
|
$this->hasWebp = file_exists(public_path(
|
|
str_replace(asset(''), '', $this->webpSrc)
|
|
));
|
|
}
|
|
|
|
public function render(): View
|
|
{
|
|
return view('components.web-picture');
|
|
}
|
|
}
|