{{ $original := .Page.Resources.GetMatch (.Get "src") }}
{{ $options := default "1000x" (.Get "options") }}

{{ .Scratch.Set "image" ($original.Resize $options) }}

{{ define "img" }}
  {{ $image := .Scratch.Get "image" }}
  <img src='{{ $image.RelPermalink }}' class='{{ .Get "class" }}' alt="{{ .Inner | plainify }}" style="max-width: 90%;" />
{{ end }}

{{ if .Inner }}
  <figure class="text-center">
    {{ template "img" . }}
    <figcaption class="text-center">
      <small>{{ .Inner | markdownify }}</small>
    </figcaption>
  </figure>
{{ else }}
  {{ template "img" . }}
{{ end }}