HUGO
Menu
GitHub 87548 stars Mastodon

Meta

適用於 JPEG、PNG、TIFF 和 WebP 圖像,返回包含 Exif、IPTC 和 XMP 元數據的對象。

Syntax

RESOURCE.Meta

Returns

meta.MetaInfo
New in v0.155.3

此方法可用於 全局資源頁面資源遠程資源

適用於 JPEG、PNG、TIFF 和 WebP 圖像,圖像 Resource 對象上的 Meta 方法返回包含 ExifIPTCXMP 元數據的對象。

要僅提取 Exif 元數據,請改用 Exif 方法。

元數據在圖像轉換期間不會保留。使用此方法與_原始_圖像資源一起從 JPEG、PNG、TIFF 和 WebP 圖像中提取元數據。

方法

Date

time.Time)返回圖像創建日期/時間。使用 time.Format 函數格式化。

Lat

float64)從 Exif 元數據返回 GPS 緯度(度),並回退到 XMP 元數據。

Long

float64)從 Exif 元數據返回 GPS 經度(度),並回退到 XMP 元數據。

Orientation

int)返回 Exif Orientation 標簽的值,八個可能值之一:

描述
1 水平(正常)
2 水平鏡像
3 旋轉 180 度
4 垂直鏡像
5 水平鏡像並順時針旋轉 270 度
6 順時針旋轉 90 度
7 水平鏡像並順時針旋轉 90 度
8 順時針旋轉 270 度

使用 images.AutoOrient 圖像濾鏡根據 Exif 方向標簽按需旋轉和翻轉圖像

Exif

meta.Tags)返回此圖像可用的 Exif 字段集合。可用性由 sources 設置確定,特定字段通過 fields 設置管理,兩者都在站點配置中管理。

IPTC

meta.Tags)返回此圖像可用的 IPTC 字段集合。可用性由 sources 設置確定,特定字段通過 fields 設置管理,兩者都在站點配置中管理。

XMP

meta.Tags)返回此圖像可用的 XMP 字段集合。可用性由 sources 設置確定,特定字段通過 fields 設置管理,兩者都在站點配置中管理。

示例

要列出創建日期、緯度、經度和方向:

{{ 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 }}

要列出可用的 Exif 字段:

{{ with resources.Get "images/a.jpg" }}
  {{ with .Meta }}
    <pre>
      {{ range $k, $v := .Exif -}}
        {{ printf "%-25s %v\n" $k $v }}
      {{ end }}
    </pre>
  {{ end }}
{{ end }}

要列出可用的 IPTC 字段:

{{ with resources.Get "images/a.jpg" }}
  {{ with .Meta }}
    <pre>
      {{ range $k, $v := .IPTC -}}
        {{ printf "%-25s %v\n" $k $v }}
      {{ end }}
    </pre>
  {{ end }}
{{ end }}

要列出可用的 XMP 字段:

{{ with resources.Get "images/a.jpg" }}
  {{ with .Meta }}
    <pre>
      {{ range $k, $v := .XMP -}}
        {{ printf "%-25s %v\n" $k $v }}
      {{ end }}
    </pre>
  {{ end }}
{{ end }}

要一起列出可用的 Exif、IPTC 和 XMP 字段:

{{ 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 }}

要列出特定值:

{{ 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 }}

Last updated: January 1, 0001
Improve this page