| 1 |
--- |
| 2 |
title: Meta |
| 3 |
description: Applicable to images, returns an object containing Exif, IPTC, and XMP metadata for supported image formats. |
| 4 |
categories: [] |
| 5 |
keywords: [metadata] |
| 6 |
params: |
| 7 |
functions_and_methods: |
| 8 |
returnType: meta.MetaInfo |
| 9 |
signatures: [RESOURCE.Meta] |
| 10 |
--- |
| 11 |
|
| 12 |
{{< new-in 0.155.3 />}} |
| 13 |
|
| 14 |
{{% include "/_common/methods/resource/global-page-remote-resources.md" %}} |
| 15 |
|
| 16 |
The `Meta` method on an image `Resource` object returns an object containing [Exif][], [IPTC][], and [XMP][] metadata. |
| 17 |
|
| 18 |
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. |
| 19 |
|
| 20 |
> [!NOTE] |
| 21 |
> Metadata is not preserved during image transformation. Use this method with the _original_ image resource to extract metadata from supported formats. |
| 22 |
|
| 23 |
## Usage |
| 24 |
|
| 25 |
Use the [`reflect.IsImageResourceWithMeta`][] function to verify that a resource supports metadata extraction before calling the `Meta` method. |
| 26 |
|
| 27 |
```go-html-template |
| 28 |
{{ with resources.GetMatch "images/featured.*" }} |
| 29 |
{{ if reflect.IsImageResourceWithMeta . }} |
| 30 |
{{ with .Meta }} |
| 31 |
{{ .Date.Format "2006-01-02" }} |
| 32 |
{{ end }} |
| 33 |
{{ end }} |
| 34 |
{{ end }} |
| 35 |
``` |
| 36 |
|
| 37 |
## Methods |
| 38 |
|
| 39 |
Use these methods on the `Meta` object. |
| 40 |
|
| 41 |
`Date` |
| 42 |
: (`time.Time`) Returns the image creation date/time. Format with the [`time.Format`][] function. |
| 43 |
|
| 44 |
`Lat` |
| 45 |
: (`float64`) Returns the GPS latitude in degrees from Exif metadata, with a fallback to XMP metadata. |
| 46 |
|
| 47 |
`Long` |
| 48 |
: (`float64`) Returns the GPS longitude in degrees from Exif metadata, with a fallback to XMP metadata. |
| 49 |
|
| 50 |
`Orientation` |
| 51 |
: (`int`) Returns the value of the Exif `Orientation` tag, one of eight possible values. |
| 52 |
|
| 53 |
Value|Description |
| 54 |
:--|:-- |
| 55 |
`1`|Horizontal (normal) |
| 56 |
`2`|Mirrored horizontal |
| 57 |
`3`|Rotated 180 degrees |
| 58 |
`4`|Mirrored vertical |
| 59 |
`5`|Mirrored horizontal and rotated 270 degrees clockwise |
| 60 |
`6`|Rotated 90 degrees clockwise |
| 61 |
`7`|Mirrored horizontal and rotated 90 degrees clockwise |
| 62 |
`8`|Rotated 270 degrees clockwise |
| 63 |
|
| 64 |
> [!TIP] |
| 65 |
> Use the [`images.AutoOrient`][] image filter to rotate and flip an image as needed per its Exif orientation tag |
| 66 |
|
| 67 |
`Exif` |
| 68 |
: (`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. |
| 69 |
|
| 70 |
`IPTC` |
| 71 |
: (`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. |
| 72 |
|
| 73 |
`XMP` |
| 74 |
: (`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. |
| 75 |
|
| 76 |
## Examples |
| 77 |
|
| 78 |
To list the creation date, latitude, longitude, and orientation: |
| 79 |
|
| 80 |
```go-html-template |
| 81 |
{{ with resources.GetMatch "images/featured.*" }} |
| 82 |
{{ if reflect.IsImageResourceWithMeta . }} |
| 83 |
{{ with .Meta }} |
| 84 |
<pre> |
| 85 |
{{ printf "%-25s %v\n" "Date" .Date }} |
| 86 |
{{ printf "%-25s %v\n" "Latitude" .Lat }} |
| 87 |
{{ printf "%-25s %v\n" "Longitude" .Long }} |
| 88 |
{{ printf "%-25s %v\n" "Orientation" .Orientation }} |
| 89 |
</pre> |
| 90 |
{{ end }} |
| 91 |
{{ end }} |
| 92 |
{{ end }} |
| 93 |
``` |
| 94 |
|
| 95 |
{{% include "/_common/functions/reflect/image-reflection-functions.md" %}} |
| 96 |
|
| 97 |
[Exif]: https://en.wikipedia.org/wiki/Exif |
| 98 |
[IPTC]: https://en.wikipedia.org/wiki/IPTC_Information_Interchange_Model |
| 99 |
[XMP]: https://en.wikipedia.org/wiki/Extensible_Metadata_Platform |
| 100 |
[`fields`]: /configuration/imaging/#fields |
| 101 |
[`images.AutoOrient`]: /functions/images/autoorient/ |
| 102 |
[`reflect.IsImageResourceWithMeta`]: /functions/reflect/isimageresourcewithmeta/ |
| 103 |
[`sources`]: /configuration/imaging/#sources |
| 104 |
[`time.Format`]: /functions/time/format/ |