summaryrefslogtreecommitdiffhomepage
path: root/resources/image.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2019-08-29 10:18:51 +0200
committerBjørn Erik Pedersen <[email protected]>2019-08-31 19:04:56 +0200
commit28143397d625cce1f89f4161cba97c0dddd9004c (patch)
treea0d04fd2c6d04b82bcc1060b97c8f803378da779 /resources/image.go
parent8a8d4a6d97d181f1aaee639d35b198a27bb788e2 (diff)
downloadhugo-28143397d625cce1f89f4161cba97c0dddd9004c.tar.gz
hugo-28143397d625cce1f89f4161cba97c0dddd9004c.zip
Add image.Exif
Note that we will probably need to add some metadata cache for this to scale. Fixes #4600
Diffstat (limited to 'resources/image.go')
-rw-r--r--resources/image.go49
1 files changed, 49 insertions, 0 deletions
diff --git a/resources/image.go b/resources/image.go
index 7113284f7..b06a84522 100644
--- a/resources/image.go
+++ b/resources/image.go
@@ -21,6 +21,9 @@ import (
_ "image/png"
"os"
"strings"
+ "sync"
+
+ "github.com/gohugoio/hugo/resources/images/exif"
"github.com/gohugoio/hugo/resources/internal"
@@ -48,12 +51,56 @@ var (
type imageResource struct {
*images.Image
+ // When a image is processed in a chain, this holds the reference to the
+ // original (first).
+ root *imageResource
+
+ exifInit sync.Once
+ exifInitErr error
+ exif *exif.Exif
+
baseResource
}
+// ImageData contains image related data, typically Exif.
+type ImageData map[string]interface{}
+
+func (i *imageResource) Exif() (*exif.Exif, error) {
+ return i.root.getExif()
+}
+
+func (i *imageResource) getExif() (*exif.Exif, error) {
+
+ i.exifInit.Do(func() {
+ supportsExif := i.Format == images.JPEG || i.Format == images.TIFF
+ if !supportsExif {
+ return
+ }
+
+ f, err := i.root.ReadSeekCloser()
+ if err != nil {
+ i.exifInitErr = err
+ return
+ }
+ defer f.Close()
+
+ x, err := i.getSpec().imaging.DecodeExif(f)
+ if err != nil {
+ i.exifInitErr = err
+ return
+ }
+
+ i.exif = x
+
+ })
+
+ return i.exif, i.exifInitErr
+}
+
func (i *imageResource) Clone() resource.Resource {
gr := i.baseResource.Clone().(baseResource)
return &imageResource{
+ root: i.root,
Image: i.WithSpec(gr),
baseResource: gr,
}
@@ -74,6 +121,7 @@ func (i *imageResource) cloneWithUpdates(u *transformationUpdate) (baseResource,
}
return &imageResource{
+ root: i.root,
Image: img,
baseResource: base,
}, nil
@@ -217,6 +265,7 @@ func (i *imageResource) clone(img image.Image) *imageResource {
return &imageResource{
Image: image,
+ root: i.root,
baseResource: spec,
}
}