reflect.IsImageResource
Reports whether the given value is a Resource object representing a processable image.
Syntax
reflect.IsImageResource INPUT
Returns
bool
A processable image is an image file characterized by one of the following media types:
image/gifimage/jpegimage/pngimage/tiffimage/webp
Hugo can decode and encode these image formats, allowing you to use any of the resource methods applicable to images such as Width, Height, Crop, Fill, Fit, Resize, etc.
With this project structure:
project/
├── assets/
│ ├── a.json
│ ├── b.avif
│ └── c.jpg
└── content/
└── example/
├── index.md/
├── d.json
├── e.avif
└── f.jpgThese are the values returned by the reflect.IsImageResource function:
layouts/page.html
{{ with resources.Get "a.json" }}
{{ reflect.IsImageResource . }} → false
{{ end }}
{{ with resources.Get "b.avif" }}
{{ reflect.IsImageResource . }} → false
{{ end }}
{{ with resources.Get "c.jpg" }}
{{ reflect.IsImageResource . }} → true
{{ end }}In the example above, the b.avif image is not a processable because Hugo can neither decode nor encode the AVIF image format.
layouts/page.html
{{ with .Resources.Get "d.json" }}
{{ reflect.IsImageResource . }} → false
{{ end }}
{{ with .Resources.Get "e.avif" }}
{{ reflect.IsImageResource . }} → false
{{ end }}
{{ with .Resources.Get "f.jpg" }}
{{ reflect.IsImageResource . }} → true
{{ end }}In the example above, the e.avif image is not a processable because Hugo can neither decode nor encode the AVIF image format.
layouts/page.html
{{ with site.GetPage "/example" }}
{{ reflect.IsImageResource . }} → false
{{ end }}