Back to Go Micro

Render Image

internal/website/layouts/_markup/render-image.html

6.9.01.4 KB
Original Source

{{- $image_sizes := slice "420" "789" "1019" "1430" "2048" -}} {{- $background_colour := "#020221" -}} {{- $image_quality := "q80 CatmullRom"}} {{- $alt := .Text -}} {{- $label := .Text -}} {{- $caption := "" -}} {{- if ne .Title "" -}} {{- $caption = .Title | $.Page.RenderString -}} {{- $label = $caption -}} {{- end -}} {{- $image := .Page.Resources.GetMatch .Destination -}} {{- if and (not $image) .Page.File -}} {{- $image = resources.Get (path.Join .Page.File.Dir .Destination) -}} {{- else if not $image -}} {{- $image = resources.Get .Destination -}} {{- end -}} {{- with $image -}} {{- $image_width := $image.Width -}} {{- $image_height := $image.Height -}} {{- if strings.Contains $image "_2x" -}} {{- $image_width = math.Floor (math.Div $image_width 2) -}} {{- $image_height = math.Floor (math.Div $image_height 2) -}} {{- end -}} {{- $fallback_image := ($image.Resize (print "789x jpg " $background_colour " " $image_quality)) -}} {{- $GIP_colors := $image.Colors -}} {{- if (lt ($GIP_colors | len) 2) -}} {{- $GIP_colors = $GIP_colors | append $background_colour -}} {{- end -}} {{- $GIP_gradient := delimit ($GIP_colors) ", " -}} {{- $GIP_style := print "background: linear-gradient(" $GIP_gradient ");" -}} {{- $caption -}} {{- end -}}