Backend: Add fields to Meta.Data struct #243
Added: Subject, Keywords, Comment, CameraOwner and CameraSerial Todo: Read values from Exif.Image.XPTitle, XPSubject, XPKeywords,... Signed-off-by: Michael Mayer <michael@liquidbytes.net>
This commit is contained in:
parent
3ed5370439
commit
c13e39e6d1
6 changed files with 55 additions and 3 deletions
|
@ -11,11 +11,16 @@ type Data struct {
|
|||
TakenAtLocal time.Time
|
||||
TimeZone string
|
||||
Title string
|
||||
Subject string
|
||||
Keywords string
|
||||
Comment string
|
||||
Artist string
|
||||
Description string
|
||||
Copyright string
|
||||
CameraMake string
|
||||
CameraModel string
|
||||
CameraOwner string
|
||||
CameraSerial string
|
||||
LensMake string
|
||||
LensModel string
|
||||
Flash bool
|
||||
|
|
|
@ -136,6 +136,14 @@ func Exif(filename string) (data Data, err error) {
|
|||
data.CameraMake = strings.Replace(value, "\"", "", -1)
|
||||
}
|
||||
|
||||
if value, ok := tags["CameraOwnerName"]; ok {
|
||||
data.CameraOwner = strings.Replace(value, "\"", "", -1)
|
||||
}
|
||||
|
||||
if value, ok := tags["BodySerialNumber"]; ok {
|
||||
data.CameraSerial = strings.Replace(value, "\"", "", -1)
|
||||
}
|
||||
|
||||
if value, ok := tags["LensMake"]; ok {
|
||||
data.LensMake = strings.Replace(value, "\"", "", -1)
|
||||
}
|
||||
|
@ -199,12 +207,20 @@ func Exif(filename string) (data Data, err error) {
|
|||
if i, err := strconv.Atoi(value); err == nil {
|
||||
data.Width = i
|
||||
}
|
||||
} else if value, ok := tags["PixelXDimension"]; ok {
|
||||
if i, err := strconv.Atoi(value); err == nil {
|
||||
data.Width = i
|
||||
}
|
||||
}
|
||||
|
||||
if value, ok := tags["ImageLength"]; ok {
|
||||
if i, err := strconv.Atoi(value); err == nil {
|
||||
data.Height = i
|
||||
}
|
||||
} else if value, ok := tags["PixelYDimension"]; ok {
|
||||
if i, err := strconv.Atoi(value); err == nil {
|
||||
data.Height = i
|
||||
}
|
||||
}
|
||||
|
||||
if value, ok := tags["Orientation"]; ok {
|
||||
|
|
|
@ -26,6 +26,8 @@ func TestExif(t *testing.T) {
|
|||
assert.Equal(t, 0, data.Altitude)
|
||||
assert.Equal(t, "HUAWEI", data.CameraMake)
|
||||
assert.Equal(t, "ELE-L29", data.CameraModel)
|
||||
assert.Equal(t, "", data.CameraOwner)
|
||||
assert.Equal(t, "", data.CameraSerial)
|
||||
assert.Equal(t, 27, data.FocalLength)
|
||||
assert.Equal(t, 1, int(data.Orientation))
|
||||
|
||||
|
@ -33,6 +35,35 @@ func TestExif(t *testing.T) {
|
|||
// assert.Equal(t, "HUAWEI P30 Rear Main Camera", data.LensModel)
|
||||
})
|
||||
|
||||
t.Run("ladybug jpg file", func(t *testing.T) {
|
||||
data, err := Exif("testdata/ladybug.jpg")
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// t.Logf("all: %+v", data.All)
|
||||
|
||||
assert.Equal(t, "Photographer: TMB", data.Artist)
|
||||
assert.Equal(t, "2011-07-10T17:34:28Z", data.TakenAt.Format("2006-01-02T15:04:05Z"))
|
||||
assert.Equal(t, "2011-07-10T19:34:28Z", data.TakenAtLocal.Format("2006-01-02T15:04:05Z"))
|
||||
assert.Equal(t, "", data.Title) // Should be "Ladybug"
|
||||
assert.Equal(t, "", data.Keywords) // Should be "Ladybug"
|
||||
assert.Equal(t, "", data.Description)
|
||||
assert.Equal(t, "", data.Copyright)
|
||||
assert.Equal(t, 540, data.Height)
|
||||
assert.Equal(t, 720, data.Width)
|
||||
assert.Equal(t, 51.25485166666667, data.Lat)
|
||||
assert.Equal(t, 7.389468333333333, data.Lng)
|
||||
assert.Equal(t, 0, data.Altitude)
|
||||
assert.Equal(t, "Canon", data.CameraMake)
|
||||
assert.Equal(t, "Canon EOS 50D", data.CameraModel)
|
||||
assert.Equal(t, "Thomas Meyer-Boudnik", data.CameraOwner)
|
||||
assert.Equal(t, "2260716910", data.CameraSerial)
|
||||
assert.Equal(t, 100, data.FocalLength)
|
||||
assert.Equal(t, 1, int(data.Orientation))
|
||||
})
|
||||
|
||||
t.Run("png file without exif", func(t *testing.T) {
|
||||
_, err := Exif("testdata/tweethog.png")
|
||||
|
||||
|
|
BIN
internal/meta/testdata/ladybug.jpg
vendored
Normal file
BIN
internal/meta/testdata/ladybug.jpg
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 94 KiB |
|
@ -977,7 +977,7 @@ func TestMediaFile_AspectRatio(t *testing.T) {
|
|||
mediaFile, err := NewMediaFile(conf.ExamplesPath() + "/iphone_7.heic")
|
||||
assert.Nil(t, err)
|
||||
ratio := mediaFile.AspectRatio()
|
||||
assert.Equal(t, float64(0), ratio)
|
||||
assert.Equal(t, 0.75, ratio)
|
||||
})
|
||||
t.Run("/fern_green.jpg", func(t *testing.T) {
|
||||
conf := config.TestConfig()
|
||||
|
|
|
@ -167,8 +167,8 @@ func TestMediaFile_Exif_HEIF(t *testing.T) {
|
|||
assert.Equal(t, 34.79745, jpegInfo.Lat)
|
||||
assert.Equal(t, 134.76463333333334, jpegInfo.Lng)
|
||||
assert.Equal(t, 0, jpegInfo.Altitude)
|
||||
assert.Equal(t, 0, jpegInfo.Width)
|
||||
assert.Equal(t, 0, jpegInfo.Height)
|
||||
assert.Equal(t, 4032, jpegInfo.Width)
|
||||
assert.Equal(t, 3024, jpegInfo.Height)
|
||||
assert.Equal(t, false, jpegInfo.Flash)
|
||||
assert.Equal(t, "", jpegInfo.Description)
|
||||
|
||||
|
|
Loading…
Reference in a new issue