reflect.IsImageResource
Reports whether the given value is a Resource object representing a processable image.
Syntax
reflect.IsImageResource INPUT
Returns
bool
processable image(可處理圖像)是具有以下 media types(媒體類型)之一的圖像文件:
image/gifimage/jpegimage/pngimage/tiffimage/webp
Hugo 可以解碼和編碼這些圖像格式,允許您使用適用於圖像的 resource methods(資源方法),如 Width、Height、Crop、Fill、Fit、Resize 等�
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 image 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 image because Hugo can neither decode nor encode the AVIF image format.
layouts/page.html
{{ with site.GetPage "/example" }}
{{ reflect.IsImageResource . }} → false
{{ end }}