{{/*.src is the image path*/}} {{/*.height is used for resizing*/}} {{/*.width is used for resizing*/}} {{/*.scale is used for resizing*/}} {{/*.alt alternate text*/}} {{/*.class is added to the image*/}} {{/*.pictureclass is added to the picture*/}} {{ $img := resources.Get .src }} {{ if $img }} {{- $target1 := "" -}} {{- $target2 := "" -}} {{- if (and .width .height) }} {{/* {{ warnf "lazypicture.html: width and height" }}*/}} {{ $swidth := int .width }} {{ $sheight := int .height }} {{- $target1 = (printf "%dx%d" $swidth $sheight) -}} {{- $target2 = (printf "%dx%d" (mul 2 $swidth) (mul 2 $sheight)) -}} {{- else if .width }} {{/* {{ warnf "lazypicture.html: width" }}*/}} {{ $swidth := int .width }} {{- $target1 = (printf "%dx" $swidth) -}} {{- $target2 = (printf "%dx" (mul 2 $swidth)) -}} {{- else if .height }} {{/* {{ warnf "lazypicture.html: height" }}*/}} {{ $sheight := int .height }} {{- $target1 = (printf "x%d" $sheight) -}} {{- $target2 = (printf "x%d" (mul 2 $sheight)) -}} {{- else if .scale }} {{/* {{ warnf "lazypicture.html: scale" }}*/}} {{ $swidth := int (mul (float $img.Width) (float .scale) ) }} {{ $sheight := int (mul (float $img.Height) (float .scale) ) }} {{- $target1 = (printf "%dx%d" $swidth $sheight) -}} {{- $target2 = (printf "%dx%d" (mul 2 $swidth) (mul 2 $sheight)) -}} {{ else }} {{- $target1 = (printf "%dx%d" $img.Width $img.Height) -}} {{ end }} {{/* {{ warnf "lazypicture.html: target1 %s" $target1 }}*/}} {{ $imgOri := $img.Resize (printf "%s q75 Lanczos picture" $target1) }} {{ $imgWebp := $img.Resize (printf "%s webp q75 Lanczos picture" $target1) }} {{- if $target2 }} {{ $imgOri2 := $img.Resize (printf "%s q75 Lanczos picture" $target2) }} {{ $imgWebp2 := $img.Resize (printf "%s webp q75 Lanczos picture" $target2) }} {{- else }} {{- end }} {{ .alt }} {{ else }} {{ warnf "lazypicture.html: Image src was not found: %q" .src }} {{ end }}