aboutsummaryrefslogtreecommitdiff
path: root/layouts/shortcodes/img.html
blob: 65ca44f3439e500e6f5843264fe04f71cccb50ae (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
<!-- https://gohugo.io/content-management/image-processing/ -->

<!-- Get image -->
{{ $image := resources.GetMatch (.Get "src") }}

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

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

{{ $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 }}" />
	<figcaption>{{ $alt }}</figcaption>
</figure>