2020-01-07 17:36:49 +01:00
|
|
|
package meta
|
|
|
|
|
|
|
|
import (
|
2020-05-14 11:57:26 +02:00
|
|
|
"math"
|
2020-01-07 17:36:49 +01:00
|
|
|
"time"
|
2020-07-23 15:34:20 +02:00
|
|
|
|
|
|
|
"github.com/photoprism/photoprism/pkg/rnd"
|
2021-11-27 18:41:10 +01:00
|
|
|
"github.com/photoprism/photoprism/pkg/s2"
|
2020-01-07 17:36:49 +01:00
|
|
|
)
|
|
|
|
|
2022-01-05 16:37:19 +01:00
|
|
|
const (
|
|
|
|
ImageTypeHDR = 3 // see https://exiftool.org/TagNames/Apple.html
|
|
|
|
)
|
|
|
|
|
2022-03-28 15:57:29 +02:00
|
|
|
// Data represents image metadata.
|
2020-01-07 17:36:49 +01:00
|
|
|
type Data struct {
|
2022-01-06 09:55:41 +01:00
|
|
|
FileName string `meta:"FileName"`
|
2022-01-05 16:37:19 +01:00
|
|
|
DocumentID string `meta:"BurstUUID,MediaGroupUUID,ImageUniqueID,OriginalDocumentID,DocumentID"`
|
2020-05-27 13:40:21 +02:00
|
|
|
InstanceID string `meta:"InstanceID,DocumentID"`
|
2022-04-13 22:17:59 +02:00
|
|
|
TakenAt time.Time `meta:"DateTimeOriginal,CreationDate,CreateDate,MediaCreateDate,ContentCreateDate,DateTimeDigitized,DateTime,SubSecDateTimeOriginal,SubSecCreateDate"`
|
|
|
|
TakenAtLocal time.Time `meta:"DateTimeOriginal,CreationDate,CreateDate,MediaCreateDate,ContentCreateDate,DateTimeDigitized,DateTime,SubSecDateTimeOriginal,SubSecCreateDate"`
|
|
|
|
TakenGps time.Time `meta:"GPSDateTime,GPSDateStamp"`
|
|
|
|
TakenNs int `meta:"-"`
|
2020-05-13 21:22:49 +02:00
|
|
|
TimeZone string `meta:"-"`
|
2020-05-15 09:39:32 +02:00
|
|
|
Duration time.Duration `meta:"Duration,MediaDuration,TrackDuration"`
|
2022-04-13 22:17:59 +02:00
|
|
|
FPS float64 `meta:"VideoFrameRate,VideoAvgFrameRate"`
|
|
|
|
Frames int `meta:"FrameCount"`
|
2022-02-07 12:41:11 +01:00
|
|
|
Codec string `meta:"CompressorID,FileType"`
|
2020-05-13 21:22:49 +02:00
|
|
|
Title string `meta:"Title"`
|
2020-12-31 13:51:31 +01:00
|
|
|
Subject string `meta:"Subject,PersonInImage,ObjectName,HierarchicalSubject,CatalogSets"`
|
2021-04-25 14:17:34 +02:00
|
|
|
Keywords Keywords `meta:"Keywords"`
|
2022-04-13 22:17:59 +02:00
|
|
|
Notes string `meta:"Comment"`
|
|
|
|
Artist string `meta:"Artist,Creator,OwnerName,Owner"`
|
2020-05-13 21:22:49 +02:00
|
|
|
Description string `meta:"Description"`
|
2022-04-13 22:17:59 +02:00
|
|
|
Copyright string `meta:"Rights,Copyright,WebStatement,Certificate"`
|
|
|
|
License string `meta:"UsageTerms,License"`
|
2020-07-16 13:02:48 +02:00
|
|
|
Projection string `meta:"ProjectionType"`
|
2021-12-09 07:00:39 +01:00
|
|
|
ColorProfile string `meta:"ICCProfileName,ProfileDescription"`
|
2020-05-13 21:22:49 +02:00
|
|
|
CameraMake string `meta:"CameraMake,Make"`
|
|
|
|
CameraModel string `meta:"CameraModel,Model"`
|
|
|
|
CameraOwner string `meta:"OwnerName"`
|
|
|
|
CameraSerial string `meta:"SerialNumber"`
|
|
|
|
LensMake string `meta:"LensMake"`
|
|
|
|
LensModel string `meta:"Lens,LensModel"`
|
2022-04-13 22:17:59 +02:00
|
|
|
Software string `meta:"Software,HistorySoftwareAgent,ProcessingSoftware"`
|
2020-05-13 21:22:49 +02:00
|
|
|
Flash bool `meta:"-"`
|
2021-12-09 07:00:39 +01:00
|
|
|
FocalLength int `meta:"FocalLength"`
|
2020-05-13 21:22:49 +02:00
|
|
|
Exposure string `meta:"ExposureTime"`
|
|
|
|
Aperture float32 `meta:"ApertureValue"`
|
|
|
|
FNumber float32 `meta:"FNumber"`
|
|
|
|
Iso int `meta:"ISO"`
|
2022-01-05 16:37:19 +01:00
|
|
|
ImageType int `meta:"HDRImageType"`
|
2020-05-13 21:22:49 +02:00
|
|
|
GPSPosition string `meta:"GPSPosition"`
|
2020-05-14 11:57:26 +02:00
|
|
|
GPSLatitude string `meta:"GPSLatitude"`
|
|
|
|
GPSLongitude string `meta:"GPSLongitude"`
|
|
|
|
Lat float32 `meta:"-"`
|
|
|
|
Lng float32 `meta:"-"`
|
2021-07-12 21:41:44 +02:00
|
|
|
Altitude int `meta:"GlobalAltitude,GPSAltitude"`
|
2020-05-18 17:38:14 +02:00
|
|
|
Width int `meta:"PixelXDimension,ImageWidth,ExifImageWidth,SourceImageWidth"`
|
|
|
|
Height int `meta:"PixelYDimension,ImageHeight,ImageLength,ExifImageHeight,SourceImageHeight"`
|
2020-05-13 21:22:49 +02:00
|
|
|
Orientation int `meta:"-"`
|
2020-05-14 14:28:23 +02:00
|
|
|
Rotation int `meta:"Rotation"`
|
2020-07-11 16:46:29 +02:00
|
|
|
Views int `meta:"-"`
|
|
|
|
Albums []string `meta:"-"`
|
2020-05-27 13:40:21 +02:00
|
|
|
Error error `meta:"-"`
|
2022-04-09 19:56:38 +02:00
|
|
|
exif map[string]string
|
2020-01-07 17:36:49 +01:00
|
|
|
}
|
2020-05-14 11:57:26 +02:00
|
|
|
|
2020-07-11 16:46:29 +02:00
|
|
|
// NewData creates a new metadata struct.
|
|
|
|
func NewData() Data {
|
2022-04-09 19:56:38 +02:00
|
|
|
return Data{}
|
2020-07-11 16:46:29 +02:00
|
|
|
}
|
|
|
|
|
2020-05-14 11:57:26 +02:00
|
|
|
// AspectRatio returns the aspect ratio based on width and height.
|
|
|
|
func (data Data) AspectRatio() float32 {
|
2020-06-04 14:56:27 +02:00
|
|
|
width := float64(data.ActualWidth())
|
|
|
|
height := float64(data.ActualHeight())
|
2020-05-14 11:57:26 +02:00
|
|
|
|
|
|
|
if width <= 0 || height <= 0 {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2020-07-21 10:52:39 +02:00
|
|
|
aspectRatio := float32(math.Round((width/height)*100) / 100)
|
2020-05-14 11:57:26 +02:00
|
|
|
|
|
|
|
return aspectRatio
|
|
|
|
}
|
|
|
|
|
2022-01-05 11:40:44 +01:00
|
|
|
// Portrait returns true if it is a portrait picture or video based on width and height.
|
2020-05-14 11:57:26 +02:00
|
|
|
func (data Data) Portrait() bool {
|
2020-08-28 09:27:25 +02:00
|
|
|
return data.ActualWidth() < data.ActualHeight()
|
2020-05-14 11:57:26 +02:00
|
|
|
}
|
|
|
|
|
2022-01-05 16:37:19 +01:00
|
|
|
// IsHDR tests if it is a high dynamic range file.
|
|
|
|
func (data Data) IsHDR() bool {
|
|
|
|
return data.ImageType == ImageTypeHDR
|
|
|
|
}
|
|
|
|
|
2020-05-14 11:57:26 +02:00
|
|
|
// Megapixels returns the resolution in megapixels.
|
|
|
|
func (data Data) Megapixels() int {
|
|
|
|
return int(math.Round(float64(data.Width*data.Height) / 1000000))
|
|
|
|
}
|
2020-05-27 13:40:21 +02:00
|
|
|
|
|
|
|
// HasDocumentID returns true if a DocumentID exists.
|
|
|
|
func (data Data) HasDocumentID() bool {
|
2020-07-23 15:34:20 +02:00
|
|
|
return rnd.IsUUID(data.DocumentID)
|
2020-05-27 13:40:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// HasInstanceID returns true if an InstanceID exists.
|
|
|
|
func (data Data) HasInstanceID() bool {
|
2020-07-23 15:34:20 +02:00
|
|
|
return rnd.IsUUID(data.InstanceID)
|
2020-05-27 13:40:21 +02:00
|
|
|
}
|
|
|
|
|
2021-02-05 09:45:28 +01:00
|
|
|
// HasTimeAndPlace if data contains a time and GPS position.
|
2020-05-27 13:40:21 +02:00
|
|
|
func (data Data) HasTimeAndPlace() bool {
|
|
|
|
return !data.TakenAt.IsZero() && data.Lat != 0 && data.Lng != 0
|
|
|
|
}
|
2020-06-04 14:56:27 +02:00
|
|
|
|
|
|
|
// ActualWidth is the width after rotating the media file if needed.
|
|
|
|
func (data Data) ActualWidth() int {
|
|
|
|
if data.Orientation > 4 {
|
|
|
|
return data.Height
|
|
|
|
}
|
|
|
|
|
|
|
|
return data.Width
|
|
|
|
}
|
|
|
|
|
|
|
|
// ActualHeight is the height after rotating the media file if needed.
|
|
|
|
func (data Data) ActualHeight() int {
|
|
|
|
if data.Orientation > 4 {
|
|
|
|
return data.Width
|
|
|
|
}
|
|
|
|
|
|
|
|
return data.Height
|
|
|
|
}
|
2020-12-04 19:51:51 +01:00
|
|
|
|
|
|
|
// CellID returns the S2 cell ID.
|
|
|
|
func (data Data) CellID() string {
|
|
|
|
return s2.PrefixedToken(float64(data.Lat), float64(data.Lng))
|
|
|
|
}
|