actuel-inactuel/site/config/thumbs.php
isUnknown 62144384ce optimize image blocks with responsive srcset and webp conversion
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-23 22:08:04 +01:00

44 lines
1.2 KiB
PHP

<?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),
),
];