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
|
|
|
)
|
|
|
|
|
2020-01-07 18:13:53 +01:00
|
|
|
// Data represents image meta data.
|
2020-01-07 17:36:49 +01:00
|
|
|
type Data struct {
|
2020-05-27 13:40:21 +02:00
|
|
|
DocumentID string `meta:"ImageUniqueID,OriginalDocumentID,DocumentID"`
|
|
|
|
InstanceID string `meta:"InstanceID,DocumentID"`
|
2020-12-22 07:47:16 +01:00
|
|
|
TakenAt time.Time `meta:"DateTimeOriginal,CreationDate,CreateDate,MediaCreateDate,ContentCreateDate,DateTimeDigitized,DateTime"`
|
|
|
|
TakenAtLocal time.Time `meta:"DateTimeOriginal,CreationDate,CreateDate,MediaCreateDate,ContentCreateDate,DateTimeDigitized,DateTime"`
|
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"`
|
2020-05-27 13:40:21 +02:00
|
|
|
Codec string `meta:"CompressorID,Compression,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"`
|
2020-12-31 13:51:31 +01:00
|
|
|
Notes string `meta:"-"`
|
|
|
|
Artist string `meta:"Artist,Creator,OwnerName"`
|
2020-05-13 21:22:49 +02:00
|
|
|
Description string `meta:"Description"`
|
|
|
|
Copyright string `meta:"Rights,Copyright"`
|
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"`
|
|
|
|
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"`
|
|
|
|
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:"-"`
|
2020-05-13 21:22:49 +02:00
|
|
|
All 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 {
|
|
|
|
return Data{
|
|
|
|
All: make(map[string]string),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
// Portrait returns true if it's a portrait picture or video based on width and height.
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
// 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))
|
|
|
|
}
|