{{ $imagePath:= string .Src }} {{ $image:= . }} {{ $size:= .Size }} {{ $perspective:= .Perspective | default "cover" }} {{ $position:= .Position | default "center center" }} {{ $repeat:= .Repeat | default "no-repeat" }} {{ $webp:= .Webp | default true }} {{ $context:= .Context | default . }} {{ $contentImage:= false }} {{ $assetImage:= false }} {{ $placeholder:= .Placeholder | default false }} {{ $placeholderQuality:= "40x q20" }} {{ with $context.Resources }} {{ if .GetMatch $imagePath }} {{ $contentImage = true }} {{ end }} {{ end }} {{ if fileExists (add `assets/` (string $imagePath)) }} {{ $assetImage = true }} {{ end }} {{ if or (hasPrefix $imagePath "http") (fileExists (add `static/` (string $imagePath))) }} {{ $imagePath | absURL }} {{ else if or $assetImage $contentImage }} {{ if $assetImage }} {{ $image = resources.Get $imagePath }} {{ else if $contentImage }} {{ $image = $context.Resources.GetMatch $imagePath }} {{ end }} {{ $imageExt := path.Ext $image }} {{ if eq $imageExt `.svg` }} {{ .Scratch.Set "image-height" "" }} {{ .Scratch.Set "image-width" "" }} {{ else }} {{ .Scratch.Set "image-height" $image.Height }} {{ .Scratch.Set "image-width" $image.Width }} {{ end }} {{ $imageHeight:= .Scratch.Get "image-height" }} {{ $imageWidth:= .Scratch.Get "image-width" }} {{ if or (eq $imageExt `.gif`) (eq $imageExt `.svg`) }} {{ $image.RelPermalink }} {{ else }} {{ if $size }} {{ $imageWebp:= $image.Resize (add (string $size) " webp") }} {{ if not $webp }} {{ $imageWebp = $image.Resize (string $size) }} {{ end }} {{ $placeholderImage := ($imageWebp.Resize $placeholderQuality) | images.Filter (images.GaussianBlur 5) }} {{if $placeholder}}data:image/jpeg;base64,{{ $placeholderImage.Content | base64Encode }}{{else}}{{ $imageWebp.RelPermalink }}{{end}} {{ else }} {{ $height:= string $image.Height }} {{ $width:= string $image.Width }} {{ $defaultSize:= add (add $width "x") $height }} {{ $imageWebp:= $image.Resize (add $defaultSize " webp") }} {{ if not $webp }} {{ $imageWebp = $image.Resize (string $defaultSize) }} {{ end }} {{ $placeholderImage := ($imageWebp.Resize $placeholderQuality) | images.Filter (images.GaussianBlur 5) }} {{if $placeholder}}data:image/jpeg;base64,{{ $placeholderImage.Content | base64Encode }}{{else}}{{ $imageWebp.RelPermalink }}{{end}} {{ end }} {{ end }} {{ end }}