From e1c8bb1bd5381d8ade3c699a2d6b4fb373112880 Mon Sep 17 00:00:00 2001 From: Gabriel Arakaki Giovanini Date: Sun, 25 Jun 2023 20:45:43 +0200 Subject: feat: Store image size Add image dimensions to exif fetch. --- pkg/components/media/model.go | 2 ++ pkg/database/sql/media.go | 6 ++++++ pkg/fileop/exif.go | 11 +++++++++++ 3 files changed, 19 insertions(+) (limited to 'pkg') diff --git a/pkg/components/media/model.go b/pkg/components/media/model.go index f5c9ff6..0e17e92 100644 --- a/pkg/components/media/model.go +++ b/pkg/components/media/model.go @@ -15,6 +15,8 @@ type ( } MediaEXIF struct { + Width *float64 + Height *float64 Description *string Camera *string Maker *string diff --git a/pkg/database/sql/media.go b/pkg/database/sql/media.go index 59a4b83..3446f79 100644 --- a/pkg/database/sql/media.go +++ b/pkg/database/sql/media.go @@ -21,6 +21,8 @@ type ( MediaEXIF struct { gorm.Model + Width *float64 + Height *float64 MediaID uint Media Media Description *string @@ -58,6 +60,8 @@ func (self *Media) ToModel() *media.Media { func (m *MediaEXIF) ToModel() *media.MediaEXIF { return &media.MediaEXIF{ + Height: m.Height, + Width: m.Width, Description: m.Description, Camera: m.Camera, Maker: m.Maker, @@ -188,6 +192,8 @@ func (m *MediaRepository) GetEXIF(ctx context.Context, mediaID uint) (*media.Med func (s *MediaRepository) CreateEXIF(ctx context.Context, id uint, info *media.MediaEXIF) error { media := &MediaEXIF{ MediaID: id, + Width: info.Width, + Height: info.Height, Description: info.Description, Camera: info.Camera, Maker: info.Maker, diff --git a/pkg/fileop/exif.go b/pkg/fileop/exif.go index c2449ad..79716eb 100644 --- a/pkg/fileop/exif.go +++ b/pkg/fileop/exif.go @@ -37,6 +37,17 @@ func ReadExif(path string) (*media.MediaEXIF, error) { newExif.Maker = &make } + // Get Image Size + width, err := fileInfo.GetFloat("ImageWidth") + if err == nil { + newExif.Width = &width + } + + height, err := fileInfo.GetFloat("ImageHeight") + if err == nil { + newExif.Height = &height + } + // Get lens lens, err := fileInfo.GetString("LensModel") if err == nil { -- cgit v1.2.3