aboutsummaryrefslogtreecommitdiff
path: root/layouts/shortcodes/img.html
blob: a57e1edd6f47a8712a2d9702961efd7a2e459cde (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<!-- https://gohugo.io/content-management/image-processing/ -->
<!-- Get image -->
{{- $image := resources.GetMatch (.Get "src") -}}

<!-- Get parameters -->
{{- $alt := .Get "alt" | default "" -}}
{{- $caption := .Get "caption" | default "" -}}
{{- $rotation := .Get "rotation" | default 0 -}}

<!-- Get quality -->
{{- $quality := .Get "quality" | default "original" -}}

<!-- Apply quality settings -->
{{- $q := 0 -}}
{{- $size := 0 -}}
{{- if eq $quality "low" -}}
	{{- $q = 60 -}}
	{{- $size = 600 -}}
{{- else if eq $quality "medium" -}}
	{{- $q = 75 -}}
	{{- $size = 1000 -}}
{{- else if eq $quality "high" -}}
	{{- $q = 90 -}}
	{{- $size = 1200 -}}
{{- end -}}

<!-- Make image -->
{{- if ne $quality "original" -}}
	{{- $image = $image.Resize (printf "%dx q%d r%d" $size $q $rotation) -}}
{{- end -}}

<figure>
	<img src="{{ $image.RelPermalink }}" title="{{ $alt }}" alt="{{ $alt }}" />
	{{- if ne $caption "" -}}
		<figcaption>{{ $caption }}</figcaption>
	{{- end -}}
</figure>