Meta
Syntax
Returns
Use this method with global resources, page resources, or remote resources.
The Meta method on an image Resource object returns an object containing Exif, IPTC, and XMP metadata.
While Hugo classifies many file types as images, only certain formats support metadata extraction. Supported formats include AVIF, BMP, GIF, HEIC, HEIF, JPEG, PNG, TIFF, and WebP.
Metadata is not preserved during image transformation. Use this method with the original image resource to extract metadata from supported formats.
Usage
Use the reflect.IsImageResourceWithMeta function to verify that a resource supports metadata extraction before calling the Meta method.
{{ with resources.GetMatch "images/featured.*" }}
{{ if reflect.IsImageResourceWithMeta . }}
{{ with .Meta }}
{{ .Date.Format "2006-01-02" }}
{{ end }}
{{ end }}
{{ end }}Methods
Date
(time.Time) Returns the image creation date/time. Format with the time.Format function.
Lat
(float64) Returns the GPS latitude in degrees from Exif metadata, with a fallback to XMP metadata.
Long
(float64) Returns the GPS longitude in degrees from Exif metadata, with a fallback to XMP metadata.
Orientation
(int) Returns the value of the Exif Orientation tag, one of eight possible values.
| Value | Description |
|---|---|
1 | Horizontal (normal) |
2 | Mirrored horizontal |
3 | Rotated 180 degrees |
4 | Mirrored vertical |
5 | Mirrored horizontal and rotated 270 degrees clockwise |
6 | Rotated 90 degrees clockwise |
7 | Mirrored horizontal and rotated 90 degrees clockwise |
8 | Rotated 270 degrees clockwise |
Use the images.AutoOrient image filter to rotate and flip an image as needed per its Exif orientation tag
Exif
(meta.Tags) Returns a collection of available Exif fields for this image. Availability is determined by the sources setting and specific fields are managed via the fields setting, both of which are managed in your project configuration.
IPTC
(meta.Tags) Returns a collection of available IPTC fields for this image. Availability is determined by the sources setting and specific fields are managed via the fields setting, both of which are managed in your project configuration.
XMP
(meta.Tags) Returns a collection of available XMP fields for this image. Availability is determined by the sources setting and specific fields are managed via the fields setting, both of which are managed in your project configuration.
Examples
To list the creation date, latitude, longitude, and orientation:
{{ with resources.GetMatch "images/featured.*" }}
{{ if reflect.IsImageResourceWithMeta . }}
{{ with .Meta }}
<pre>
{{ printf "%-25s %v\n" "Date" .Date }}
{{ printf "%-25s %v\n" "Latitude" .Lat }}
{{ printf "%-25s %v\n" "Longitude" .Long }}
{{ printf "%-25s %v\n" "Orientation" .Orientation }}
</pre>
{{ end }}
{{ end }}
{{ end }}Image operations
Use these functions to determine which operations Hugo supports for a given resource. While Hugo classifies a variety of file types as image resources, its ability to process them or extract metadata varies by format.
reflect.IsImageResource: Reports whether the given value is a Resource object representing an image as defined by its media type.reflect.IsImageResourceProcessable: Reports whether the given value is a Resource object representing an image from which Hugo can extract dimensions and perform processing such as converting, resizing, cropping, or filtering.reflect.IsImageResourceWithMeta: Reports whether the given value is a Resource object representing an image from which Hugo can extract dimensions and, if present, Exif, IPTC, and XMP data.
The table below shows the values these functions return for various file formats. Use it to determine which checks are required before calling specific methods in your templates.
| Format | IsImageResource | IsImageResourceProcessable | IsImageResourceWithMeta |
|---|---|---|---|
| AVIF | true | false | true |
| BMP | true | true | true |
| GIF | true | true | true |
| HEIC | true | false | true |
| HEIF | true | false | true |
| ICO | true | false | false |
| JPEG | true | true | true |
| PNG | true | true | true |
| SVG | true | false | false |
| TIFF | true | true | true |
| WebP | true | true | true |
This contrived example demonstrates how to iterate through resources and use these functions to apply the appropriate handling for each image format.
{{ range resources.Match "**" }}
{{ if reflect.IsImageResource . }}
{{ if reflect.IsImageResourceProcessable . }}
{{ with .Process "resize 300x webp" }}
<img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}" alt="">
{{ end }}
{{ else if reflect.IsImageResourceWithMeta . }}
<img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}" alt="">
{{ else }}
<img src="{{ .RelPermalink }}" alt="">
{{ end }}
{{ end }}
{{ end }}