Created
September 20, 2020 07:46
-
-
Save htakeuchi/fa4d9431aff02ddfde0efda6ecf843b1 to your computer and use it in GitHub Desktop.
HugoでイメージのリサイズとExif情報を行うShortcode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{{ $originalImage := (.Page.Resources.ByType "image").GetMatch (printf "**%s**" (.Get "src")) }} | |
{{ $noExif := .Get "noExif" }} | |
{{ $resized := "" }} | |
{{ $orientation := $originalImage.Exif.Tags.Orientation }} | |
{{ if eq $orientation 6 }} | |
{{ $resized = $originalImage.Resize "x800 q92 r270" }} | |
{{ else if (eq $orientation 8) }} | |
{{ $resized = $originalImage.Resize "x800 q92 r90"}} | |
{{ else }} | |
{{ $resized = $originalImage.Resize "800x q92"}} | |
{{ end }} | |
<div class="photoFlame"> | |
<a href="{{$originalImage.RelPermalink}}"> | |
<img src="{{$resized.RelPermalink}}" alt="{{ .Get "alt" }}"/> | |
</a> | |
{{ if (and $originalImage.Exif (ne $noExif "true")) }} | |
<div class="exifTags"> | |
{{ with $originalImage.Exif }} | |
{{ if .Tags.Make }} | |
<div class="exifElement"> | |
{{ .Tags.Make }} | |
</div> | |
{{ end }} | |
{{ if .Tags.Model }} | |
<div class="exifElement"> | |
{{ .Tags.Model }} | |
</div> | |
{{ end }} | |
{{ if .Tags.FocalLength }} | |
<div class="exifElement"> | |
{{ .Tags.FocalLength }}mm | |
</div> | |
{{ end }} | |
{{ if .Tags.ExposureTime }} | |
<div class="exifElement"> | |
{{ .Tags.ExposureTime }} | |
</div> | |
{{ end }} | |
{{ if .Tags.FNumber }} | |
<div class="exifElement"> | |
f{{ .Tags.FNumber }} | |
</div> | |
{{ end }} | |
{{ if .Tags.ISOSpeedRatings }} | |
<div class="exifElement"> | |
ISO{{ .Tags.ISOSpeedRatings }} | |
</div> | |
{{ end }} | |
{{ end }} | |
</div> | |
{{ end }} | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment