1

Préserver les GIF animés lors des transformations d'images

This commit is contained in:
2026-03-06 22:54:15 +01:00
parent d16c29fc5d
commit 3ec52dfc71
10 changed files with 90 additions and 14 deletions

View File

@@ -76,7 +76,11 @@
{{- if gt $coverDisplay.Width 1480 -}}
{{- $coverWidth = 1480 -}}
{{- end -}}
{{- $coverDisplay = $coverImage.Resize (printf "%dx webp q80" $coverWidth) -}}
{{- $coverDisplay = partial "media/process-image.html" (dict
"image" $coverImage
"action" "Resize"
"spec" (printf "%dx" $coverWidth)
) -}}
{{- end -}}
{{- end -}}
{{- end -}}

View File

@@ -100,7 +100,11 @@
{{- $title := default (printf "Image complémentaire : %s" $imageName) (index $data "title") -}}
{{- $thumbnail := . -}}
{{- if and (ne .MediaType.SubType "svg") (gt .Width 360) -}}
{{- $thumbnail = .Resize "360x webp q80" -}}
{{- $thumbnail = partial "media/process-image.html" (dict
"image" .
"action" "Resize"
"spec" "360x"
) -}}
{{- end -}}
<li>
<a href="{{ .RelPermalink }}" title="{{ $title }}">

View File

@@ -41,8 +41,6 @@
{{- $thumbnailTransform = "900x506" -}}
{{- end -}}
{{- $thumbnailOptions := printf "%s webp q80" $thumbnailTransform -}}
{{- $coverPath := $page.Params.cover -}}
{{- $image := false -}}
{{- if $coverPath -}}
@@ -111,7 +109,11 @@
<a href="{{ $page.RelPermalink }}">
<figure>
{{- with $image -}}
{{- $resized := .Fill $thumbnailOptions -}}
{{- $resized := partial "media/process-image.html" (dict
"image" .
"action" "Fill"
"spec" $thumbnailTransform
) -}}
<img src="{{ $resized.RelPermalink }}" alt="Image de couverture pour {{ $page.Title }}" loading="lazy">
{{- end -}}
</figure>
@@ -127,7 +129,11 @@
<a href="{{ $page.RelPermalink }}">
<figure>
{{- with $image -}}
{{- $resized := .Fill $thumbnailOptions -}}
{{- $resized := partial "media/process-image.html" (dict
"image" .
"action" "Fill"
"spec" $thumbnailTransform
) -}}
<img src="{{ $resized.RelPermalink }}" alt="Image de couverture pour {{ $page.Title }}" loading="lazy">
{{- end -}}
</figure>

View File

@@ -15,13 +15,21 @@
{{- if gt $image.Width $maxWidth -}}
{{- $targetWidth = $maxWidth -}}
{{- end -}}
{{- $display = $image.Resize (printf "%dx webp q80" $targetWidth) -}}
{{- $display = partial "media/process-image.html" (dict
"image" $image
"action" "Resize"
"spec" (printf "%dx" $targetWidth)
) -}}
{{- else -}}
{{- $targetHeight := $image.Height -}}
{{- if gt $image.Height 900 -}}
{{- $targetHeight = 900 -}}
{{- end -}}
{{- $display = $image.Resize (printf "x%d webp q80" $targetHeight) -}}
{{- $display = partial "media/process-image.html" (dict
"image" $image
"action" "Resize"
"spec" (printf "x%d" $targetHeight)
) -}}
{{- end -}}
{{- end -}}

View File

@@ -0,0 +1,30 @@
{{/* Préserve les GIF animés en évitant toute transformation Hugo. */}}
{{- $image := .image -}}
{{- if not $image -}}
{{- errorf "media/process-image.html: missing image resource" -}}
{{- end -}}
{{- $action := .action -}}
{{- if not $action -}}
{{- errorf "media/process-image.html: missing image action for %q" $image.Name -}}
{{- end -}}
{{- $spec := .spec -}}
{{- if not $spec -}}
{{- errorf "media/process-image.html: missing image spec for %q" $image.Name -}}
{{- end -}}
{{- $result := $image -}}
{{- $subType := lower $image.MediaType.SubType -}}
{{- if and (ne $subType "svg") (ne $subType "gif") -}}
{{- $options := printf "%s webp q80" $spec -}}
{{- if eq $action "Fill" -}}
{{- $result = $image.Fill $options -}}
{{- else if eq $action "Resize" -}}
{{- $result = $image.Resize $options -}}
{{- else -}}
{{- errorf "media/process-image.html: unsupported image action %q for %q" $action $image.Name -}}
{{- end -}}
{{- end -}}
{{- return $result -}}

View File

@@ -4,7 +4,11 @@
{{- $assetPath := "images/oeuvres/l-anankeisme.png" -}}
{{- $source := resources.Get $assetPath -}}
{{- if $source -}}
{{- $img := $source.Resize "320x webp q80" -}}
{{- $img := partial "media/process-image.html" (dict
"image" $source
"action" "Resize"
"spec" "320x"
) -}}
<img src="{{ $img.RelPermalink }}" width="{{ $img.Width }}" height="{{ $img.Height }}" alt="Couverture de L'Anankéisme" loading="lazy">
{{- end -}}
</figure>

View File

@@ -4,7 +4,11 @@
{{- $assetPath := "images/oeuvres/l-humain-cette-espece-primitive.jpeg" -}}
{{- $source := resources.Get $assetPath -}}
{{- if $source -}}
{{- $img := $source.Resize "320x webp q80" -}}
{{- $img := partial "media/process-image.html" (dict
"image" $source
"action" "Resize"
"spec" "320x"
) -}}
<img src="{{ $img.RelPermalink }}" width="{{ $img.Width }}" height="{{ $img.Height }}" alt="Couverture de L'Humain, cette espèce primitive" loading="lazy">
{{- end -}}
</figure>

View File

@@ -6,7 +6,11 @@
{{- $logo := resources.GetMatch $logoPath -}}
<a href="{{ "/" | relURL }}" aria-label="Revenir à l'accueil">
{{- with $logo -}}
{{- $resized := .Resize "64x webp q80" -}}
{{- $resized := partial "media/process-image.html" (dict
"image" .
"action" "Resize"
"spec" "64x"
) -}}
<img src="{{ $resized.RelPermalink }}" alt="">
{{- end -}}
<strong>{{ $site.Title }}</strong>

View File

@@ -36,7 +36,11 @@
{{- with $image -}}
<a href="{{ $page.RelPermalink }}">
<figure>
{{- $resized := .Fill "600x340 webp q80" -}}
{{- $resized := partial "media/process-image.html" (dict
"image" .
"action" "Fill"
"spec" "600x340"
) -}}
<img src="{{ $resized.RelPermalink }}" alt="Image de couverture pour {{ $page.Title }}" loading="lazy">
</figure>
</a>

View File

@@ -315,7 +315,11 @@
<a href="{{ $page.RelPermalink }}">
<figure>
{{- with $image -}}
{{- $resized := .Fill "166x91 webp q80" -}}
{{- $resized := partial "media/process-image.html" (dict
"image" .
"action" "Fill"
"spec" "166x91"
) -}}
<img src="{{ $resized.RelPermalink }}" alt="Capture du lien {{ $page.Title }}" loading="lazy">
{{- end -}}
</figure>
@@ -401,7 +405,11 @@
<a href="{{ $item.RelPermalink }}" title="{{ $item.Title }}">
<figure>
{{- with $itemImage -}}
{{- $resized := .Resize "x128 webp q80" -}}
{{- $resized := partial "media/process-image.html" (dict
"image" .
"action" "Resize"
"spec" "x128"
) -}}
<img src="{{ $resized.RelPermalink }}" alt="{{ $item.Title }}" title="{{ $item.Title }}" loading="lazy">
{{- end -}}
</figure>