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
44
site/config/thumbs.php
Normal file
44
site/config/thumbs.php
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Génère un preset srcset Kirby à partir d'un tableau [label => largeur_px].
|
||||
* Applique le multiplicateur et optionnellement un format (ex: 'webp').
|
||||
*/
|
||||
function srcsetPreset(array $widths, float $mult, ?string $format = null): array
|
||||
{
|
||||
$preset = [];
|
||||
foreach ($widths as $label => $px) {
|
||||
$entry = ['width' => (int) round($px * $mult)];
|
||||
if ($format !== null) {
|
||||
$entry['format'] = $format;
|
||||
}
|
||||
$preset[$label] = $entry;
|
||||
}
|
||||
return $preset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Génère une paire de presets (original + webp) depuis un tableau de widths.
|
||||
*/
|
||||
function srcsetPair(string $name, array $widths, float $mult): array
|
||||
{
|
||||
return [
|
||||
$name => srcsetPreset($widths, $mult),
|
||||
$name . '-webp' => srcsetPreset($widths, $mult, 'webp'),
|
||||
];
|
||||
}
|
||||
|
||||
// Pas de multiplicateur supplémentaire : les tailles retina sont déjà dans les widths
|
||||
$m = 1;
|
||||
|
||||
// Bloc image — desktop max 720px, retina x2 = 1440px, mobile 95vw
|
||||
$widths = [
|
||||
'block-image' => ['360w' => 360, '720w' => 720, '1080w' => 1080, '1440w' => 1440],
|
||||
];
|
||||
|
||||
return [
|
||||
'quality' => 80,
|
||||
'srcsets' => array_merge(
|
||||
srcsetPair('block-image', $widths['block-image'], $m),
|
||||
),
|
||||
];
|
||||
Loading…
Add table
Add a link
Reference in a new issue