Meta
Syntax
Returns
Use this method with global resources, page resources, or remote resources.
Applicable to JPEG, PNG, TIFF, and WebP images, the Meta method on an image Resource object returns an object containing Exif, IPTC, and XMP metadata.
To extract Exif metadata only, use the Exif method instead.
Metadata is not preserved during image transformation. Use this method with the original image resource to extract metadata from JPEG, PNG, TIFF, and WebP images.
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 site 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 site 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 site configuration.
Examples
To list the creation date, latitude, longitude, and orientation:
{{ with resources.Get "images/a.jpg" }}
{{ 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 }}To list the available Exif fields:
{{ with resources.Get "images/a.jpg" }}
{{ with .Meta }}
<pre>
{{ range $k, $v := .Exif -}}
{{ printf "%-25s %v\n" $k $v }}
{{ end }}
</pre>
{{ end }}
{{ end }}To list the available IPTC fields:
{{ with resources.Get "images/a.jpg" }}
{{ with .Meta }}
<pre>
{{ range $k, $v := .IPTC -}}
{{ printf "%-25s %v\n" $k $v }}
{{ end }}
</pre>
{{ end }}
{{ end }}To list the available XMP fields:
{{ with resources.Get "images/a.jpg" }}
{{ with .Meta }}
<pre>
{{ range $k, $v := .XMP -}}
{{ printf "%-25s %v\n" $k $v }}
{{ end }}
</pre>
{{ end }}
{{ end }}To list the available Exif, IPTC, and XMP fields together:
{{ with resources.Get "images/a.jpg" }}
{{ with .Meta }}
<pre>
{{ range $k, $v := merge .Exif .IPTC .XMP -}}
{{ printf "%-25s %v\n" $k $v }}
{{ end }}
</pre>
{{ end }}
{{ end }}To list specific values:
{{ with resources.Get "images/a.jpg" }}
{{ with .Meta }}
<pre>
{{ with .Exif.ApertureValue }}{{ printf "%-25s %v\n" "ApertureValue" . }}{{ end }}
{{ with .Exif.BrightnessValue }}{{ printf "%-25s %v\n" "BrightnessValue" . }}{{ end }}
{{ with .IPTC.Headline }}{{ printf "%-25s %v\n" "Headline" . }}{{ end }}
{{ with index .IPTC "Province-State" }}{{ printf "%-25s %v\n" "Province-State" . }}{{ end }}
{{ with .XMP.Creator }}{{ printf "%-25s %v\n" "Creator" . }}{{ end }}
{{ with .XMP.Subject }}{{ printf "%-25s %v\n" "Subject" . }}{{ end }}
</pre>
{{ end }}
{{ end }}