50 lines
1.9 KiB
HTML
50 lines
1.9 KiB
HTML
{{ $alt := .Get "alt" -}}
|
|
{{ $class := .Get "class" -}}
|
|
{{ $height := .Get "height" -}}
|
|
{{ $size := .Get "size" -}}
|
|
{{ $src := .Get "src" -}}
|
|
{{ $width := .Get "width" -}}
|
|
{{ $maxwidth := .Site.Params.imageMaxWidth -}}
|
|
{{ $realwidth := 0 -}}
|
|
{{ $realheight := 0 -}}
|
|
{{ if (fileExists (add "/assets" $src)) -}}
|
|
{{ $original := resources.Get $src -}}
|
|
{{ if $size -}}
|
|
{{ $image := $original.Resize $size -}}
|
|
{{ $src = $image.RelPermalink -}}
|
|
{{ $width = $image.Width -}}
|
|
{{ $height = $image.Height -}}
|
|
{{ else -}}
|
|
{{ $src = $original.RelPermalink -}}
|
|
{{ $realwidth = $original.Width -}}
|
|
{{ $realheight = $original.Height -}}
|
|
{{ end -}}
|
|
{{ else if (fileExists (add "/static" $src)) -}}
|
|
{{ with (imageConfig (add "/static" $src)) -}}
|
|
{{ $realwidth = .Width -}}
|
|
{{ $realheight = .Height -}}
|
|
{{ end -}}
|
|
{{ end -}}
|
|
{{ if and $width $height -}}
|
|
{{ $width = int $width -}}
|
|
{{ $height = int $height -}}
|
|
{{ else if $width -}}
|
|
{{ $width = int $width -}}
|
|
{{ $height = $realheight -}}
|
|
{{ if and ($realwidth) (lt ($width) ($realwidth)) -}}
|
|
{{ $height = (mul ($realheight) (div (add ($width) 0.0) ($realwidth))) -}}
|
|
{{ $height = (math.Round $height) -}}
|
|
{{ end -}}
|
|
{{ else if $height -}}
|
|
{{ $width = $realwidth -}}
|
|
{{ $height = int $height -}}
|
|
{{ if and ($realheight) (lt ($height) ($realheight)) -}}
|
|
{{ $width = (mul ($realwidth) (div (add ($height) 0.0) ($realheight))) -}}
|
|
{{ $width = (math.Round $width) -}}
|
|
{{ end -}}
|
|
{{ else if and ($maxwidth) (lt ($maxwidth) ($realwidth)) -}}
|
|
{{ $width = ($maxwidth) -}}
|
|
{{ $height = (mul ($realheight) (div (add ($width) 0.0) ($realwidth))) -}}
|
|
{{ $height = (math.Round $height) -}}
|
|
{{ end -}}
|
|
<img class="image{{ with $class }} {{ . }}{{ end }}" src="{{ $src }}"{{ with $alt }} alt="{{ . }}"{{ end }}{{ with $width }} width="{{ . }}"{{ end }}{{ with $height }} height="{{ . }}"{{ end }}>
|