31 lines
996 B
HTML
31 lines
996 B
HTML
{{/* 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 -}}
|