optimize image blocks with responsive srcset and webp conversion
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
31f1cd0ed5
commit
62144384ce
3 changed files with 48 additions and 3 deletions
|
|
@ -14,7 +14,7 @@ if ($block->location() == 'web') {
|
|||
} elseif ($image = $block->image()->toFile()) {
|
||||
$alt = $alt->or($image->alt());
|
||||
$src = $image->url();
|
||||
$srcset = $image->srcset([300, 600, 900, 1200, 1800]);
|
||||
$srcset = $image->srcset('block-image-webp');
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
@ -22,10 +22,10 @@ if ($block->location() == 'web') {
|
|||
<figure<?= Html::attr(['data-ratio' => $ratio, 'data-crop' => $crop], null, ' ') ?>>
|
||||
<?php if ($link->isNotEmpty()): ?>
|
||||
<a href="<?= Str::esc($link->toUrl()) ?>">
|
||||
<img src="<?= $src ?>" alt="<?= $alt->esc() ?>"<?php if ($srcset): ?> srcset="<?= $srcset ?>" sizes="min(60vw, 45rem)"<?php endif ?> loading="lazy">
|
||||
<img src="<?= $src ?>" alt="<?= $alt->esc() ?>"<?php if ($srcset): ?> srcset="<?= $srcset ?>" sizes="(min-width: 768px) 720px, 95vw"<?php endif ?> loading="lazy">
|
||||
</a>
|
||||
<?php else: ?>
|
||||
<img src="<?= $src ?>" alt="<?= $alt->esc() ?>"<?php if ($srcset): ?> srcset="<?= $srcset ?>" sizes="min(60vw, 45rem)"<?php endif ?> loading="lazy">
|
||||
<img src="<?= $src ?>" alt="<?= $alt->esc() ?>"<?php if ($srcset): ?> srcset="<?= $srcset ?>" sizes="(min-width: 768px) 720px, 95vw"<?php endif ?> loading="lazy">
|
||||
<?php endif ?>
|
||||
|
||||
<?php if ($caption->isNotEmpty()): ?>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue