{{ $img := .img }} {{ $alt := .alt }} {{ $class := .class }} {{ $lazy := .lazy | default $.Page.Site.Params.enableImageLazyLoading | default true }} {{ $webp := .webp | default $.Page.Site.Params.enableImageWebp | default true }} {{ $lqip := .lqip | default false }} {{ $x2 := .x2 | default false }} {{ with $img }} {{ if (eq .MediaType.SubType "svg") }} {{ $width := ""}} {{ $height := ""}} {{ $svgContent := .Content }} {{ range (findRESubmatch `]*width=["']([.0-9]*)["'a-zA-Z]` $svgContent 1) }} {{ $width = index . 1 }} {{ end }} {{ range (findRESubmatch `]*height=["']([.0-9]*)["'a-zA-Z]` $svgContent 1) }} {{ $height = index . 1 }} {{ end }} {{ if (eq "" $width $height) }} {{ range (findRESubmatch `]*viewBox=["']?([.0-9]*) ([.0-9]*) ([.0-9]*) ([.0-9]*)` $svgContent 1) }} {{ $width = index . 3 }} {{ $height = index . 4 }} {{ end }} {{ end }} {{ if (eq "" $width $height) }} {{ warnf "Can't detect width and height for SVG %s" .RelPermalink }} {{/* do not use lazy without dimensions */}} {{ $lazy = false }} {{ end }} {{ . }} {{ else }} {{ $width := .Width }} {{ $height := .Height }} {{ if $x2 }} {{ $width = div .Width 2 }} {{ $height = div .Height 2 }} {{ end }} {{ if $webp }} {{ end }} {{ with $img }} {{ $orientation := 1 }} {{ with .Exif }} {{ $orientation = .Tags.Orientation }} {{ end }} {{ if eq $orientation 1 }} {{ . }} {{ else if (eq $orientation 8) }} {{ . }} {{ end }} {{ end }} {{ end }} {{ end }}