Add image.Exif

Note that we will probably need to add some metadata cache for this to scale.

Fixes #4600
This commit is contained in:
Bjørn Erik Pedersen
2019-08-29 10:18:51 +02:00
parent 8a8d4a6d97
commit 28143397d6
12 changed files with 483 additions and 2 deletions

View File

@@ -22,6 +22,8 @@ import (
"io"
"sync"
"github.com/gohugoio/hugo/resources/images/exif"
"github.com/disintegration/gift"
"golang.org/x/image/bmp"
"golang.org/x/image/tiff"
@@ -154,8 +156,33 @@ func (i *Image) initConfig() error {
return nil
}
func NewImageProcessor(cfg Imaging) (*ImageProcessor, error) {
e := cfg.Exif
exifDecoder, err := exif.NewDecoder(
exif.WithDateDisabled(e.DisableDate),
exif.WithLatLongDisabled(e.DisableLatLong),
exif.ExcludeFields(e.ExcludeFields),
exif.IncludeFields(e.IncludeFields),
)
if err != nil {
return nil, err
}
return &ImageProcessor{
Cfg: cfg,
exifDecoder: exifDecoder,
}, nil
}
type ImageProcessor struct {
Cfg Imaging
Cfg Imaging
exifDecoder *exif.Decoder
}
func (p *ImageProcessor) DecodeExif(r io.Reader) (*exif.Exif, error) {
return p.exifDecoder.Decode(r)
}
func (p *ImageProcessor) ApplyFiltersFromConfig(src image.Image, conf ImageConfig) (image.Image, error) {