Exif
适用于 JPEG、PNG、TIFF 和 WebP 图像,返回包含 Exif 元数据的对象。
Syntax
RESOURCE.Exif
Returns
meta.ExifInfo
适用于 JPEG、PNG、TIFF 和 WebP 图像,图像 Resource 对象上的 Exif 方法返回包含 Exif 元数据的对象。
要提取 Exif、IPTC 和 XMP 元数据,请改用 Meta 方法。
元数据在图像转换期间不会保留。使用此方法与_原始_图像资源一起从 JPEG、PNG、TIFF 和 WebP 图像中提取元数据。
方法
Date
(time.Time)返回图像创建日期/时间。使用 time.Format 函数格式化。
Lat
(float64)从 Exif 元数据返回 GPS 纬度(度)。
Long
(float64)从 Exif 元数据返回 GPS 经度(度)。
Tags
(meta.Tags)返回此图像可用的 Exif 字段集合。可用性由站点配置中的 includeFields 和 excludeFields 设置确定。
示例
要列出创建日期、纬度和经度:
{{ with resources.Get "images/a.jpg" }}
{{ with .Exif }}
<pre>
{{ printf "%-25s %v\n" "Date" .Date }}
{{ printf "%-25s %v\n" "Latitude" .Lat }}
{{ printf "%-25s %v\n" "Longitude" .Long }}
</pre>
{{ end }}
{{ end }}要列出可用的 Exif 字段:
{{ with resources.Get "images/a.jpg" }}
{{ with .Exif }}
<pre>
{{ range $k, $v := .Tags -}}
{{ printf "%-25s %v\n" $k $v }}
{{ end }}
</pre>
{{ end }}
{{ end }}要列出特定的 Exif 字段:
{{ with resources.Get "images/a.jpg" }}
{{ with .Exif }}
<pre>
{{ with .Tags.ApertureValue }}{{ printf "%-25s %v\n" "ApertureValue" . }}{{ end }}
{{ with .Tags.BrightnessValue }}{{ printf "%-25s %v\n" "BrightnessValue" . }}{{ end }}
</pre>
{{ end }}
{{ end }}