{{ $width := .width }}
{{ $height := default $width .height }}
{{ $class := .class }}
{{ $resource := .resource }}
{{ $alt := .alt }}

{{ with $resource }}
  {{ $image := .Fit (printf "%dx%d webp" (int $width) (int $height)) }}
  {{ $fallback := .Fit (printf "%dx%d" (int $width) (int $height)) }}
  <picture class="{{ $class }} block">
    <source srcset="{{ $image.RelPermalink }}" type="image/webp">
    <img 
      src="{{ $fallback.RelPermalink }}" 
      alt="{{ $alt }}"
      width="{{ $width }}"
      height="{{ $height }}"
      loading="lazy">
  </picture>
{{ end }}
