From 0971dccc2bf101c5e140aa9e560359de3d3bee80 Mon Sep 17 00:00:00 2001 From: Ben Carlsson Date: Wed, 4 Jun 2025 22:42:45 -0700 Subject: [PATCH] Optimize image build --- document/img.go | 13 +++++++++++++ document/winter.go | 17 ++++++++++------- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/document/img.go b/document/img.go index 26b734e..3819b2d 100644 --- a/document/img.go +++ b/document/img.go @@ -92,6 +92,19 @@ func NewIMG(logger *slog.Logger, src string, cfg *Config) (*img, error) { }, nil } +// LoadEXIF populates im's EXIF information without decoding the entire image. +func (im *img) LoadEXIF() error { + f, err := os.Open(im.SourcePath) + if err != nil { + return fmt.Errorf("can't read %q: %w", im.SourcePath, err) + } + defer f.Close() + if err := im.loadEXIF(f); err != nil { + return fmt.Errorf("cannot get camera for %q: %w", im.SourcePath, err) + } + return nil +} + func (im *img) Load(r io.Reader) error { if err := im.loadEXIF(r); err != nil { return fmt.Errorf( diff --git a/document/winter.go b/document/winter.go index 9b0df9d..5166499 100644 --- a/document/winter.go +++ b/document/winter.go @@ -326,6 +326,16 @@ func (s *Substructure) ExecuteAll(dist string) error { im.WebPath, ) } + fresh, err := im.generatedPhotosAreFresh(im.SourcePath) + if err != nil { + return fmt.Errorf("cannot check freshness of %q: %w", im.SourcePath, err) + } + if fresh { + if err := im.LoadEXIF(); err != nil { + return fmt.Errorf("cannot load exif for %q: %w", im.SourcePath, err) + } + continue + } srcf, err := os.Open(im.SourcePath) if err != nil { return fmt.Errorf("cannot open image: %w", err) @@ -335,13 +345,6 @@ func (s *Substructure) ExecuteAll(dist string) error { if err := im.Load(srcf); err != nil { return fmt.Errorf("cannot load image: %w", err) } - fresh, err := im.generatedPhotosAreFresh(im.SourcePath) - if err != nil { - return fmt.Errorf("cannot check freshness of %q: %w", im.SourcePath, err) - } - if fresh { - continue - } if err := os.MkdirAll(filepath.Dir(dest), 0o755); err != nil { return fmt.Errorf("cannot make gallery dir %q: %w", filepath.Dir(dest), err) } -- knotmirror 0.0.1