{{- $img := .img -}} {{- $hint := default ( index $img.Params "hint" ) "" }} {{- $size := cond ( isset . "size" ) .size "" }} {{- $isResizable := not ( in ( slice "avif" "svg" "gif" ) $img.MediaType.SubType ) -}} {{- $format := cond ( isset . "format" ) .format "webp" }} {{- $permalink := "" -}} {{- if ( not ( isset . "img" ) ) -}} {{- errorf "No img set" -}} {{- end -}} {{- if ne .img.MediaType.MainType "image" -}} {{- errorf "Image '%q' is not an image" .img }} {{- end -}} {{- if ( isset . "size" ) -}} {{- if $isResizable -}} {{- $width := ( first 1 ( split .size "x" ) ) -}} {{- if gt $width $img.Width -}} {{- warnf "Requested size %s is more than image width %d (%q)" $width $img.Width $img.File.Path -}} {{- end -}} {{- else -}} {{- warnf "Size set on non-resizable image of type %s; ignoring" $img.MediaType.SubType -}} {{- end -}} {{- end -}} {{- if $isResizable -}} {{- if $size -}} {{- if eq $size "same" -}} {{- $permalink = ( $img.Process ( printf "%s %s" $format $hint ) ).RelPermalink -}} {{- else -}} {{- $permalink = ( $img.Resize ( printf "%s %s %s" $size $format $hint ) ).RelPermalink -}} {{- end -}} {{- else -}} {{- if gt $img.Width 1200 -}} {{- $permalink = ( $img.Resize ( printf "1200x %s %s" $format $hint ) ).RelPermalink -}} {{- else if gt $img.Width 800 -}} {{- $permalink = ( $img.Resize ( printf "800x %s %s" $format $hint ) ).RelPermalink -}} {{- else -}} {{- $permalink = ( $img.Process ( printf "%s %s" $format $hint ) ).RelPermalink -}} {{- end -}} {{- end -}} {{- else }} {{- $permalink = $img.RelPermalink -}} {{- end -}} {{- return $permalink -}}