Backend: Swap width and height to fix rotation when reading from JSON
Signed-off-by: Michael Mayer <michael@liquidbytes.net>
This commit is contained in:
parent
160977fec4
commit
2c564ed145
6 changed files with 223 additions and 19 deletions
|
@ -40,6 +40,7 @@ type Data struct {
|
|||
Width int `meta:"ImageWidth"`
|
||||
Height int `meta:"ImageHeight"`
|
||||
Orientation int `meta:"-"`
|
||||
Rotation int `meta:"Rotation"`
|
||||
All map[string]string
|
||||
}
|
||||
|
||||
|
|
|
@ -131,5 +131,11 @@ func (data *Data) JSON(filename string) (err error) {
|
|||
}
|
||||
}
|
||||
|
||||
// Fix rotation.
|
||||
if data.Rotation == 90 || data.Rotation == 270 || data.Rotation == -90 {
|
||||
data.Width, data.Height = data.Height, data.Width
|
||||
data.Rotation = 0
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -7,6 +7,72 @@ import (
|
|||
)
|
||||
|
||||
func TestJSON(t *testing.T) {
|
||||
t.Run("gopher-telegram.json", func(t *testing.T) {
|
||||
data, err := JSON("testdata/gopher-telegram.json")
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// t.Logf("DATA: %+v", data)
|
||||
|
||||
assert.Equal(t, "2s", data.Duration.String())
|
||||
assert.Equal(t, "2020-05-11 14:18:35 +0000 UTC", data.TakenAtLocal.String())
|
||||
assert.Equal(t, "2020-05-11 14:18:35 +0000 UTC", data.TakenAt.String())
|
||||
assert.Equal(t, "", data.TimeZone)
|
||||
assert.Equal(t, 270, data.Width)
|
||||
assert.Equal(t, 480, data.Height)
|
||||
assert.Equal(t, float32(0), data.Lat)
|
||||
assert.Equal(t, float32(0), data.Lng)
|
||||
assert.Equal(t, "", data.CameraMake)
|
||||
assert.Equal(t, "", data.CameraModel)
|
||||
assert.Equal(t, "", data.LensModel)
|
||||
})
|
||||
|
||||
t.Run("gopher-original.json", func(t *testing.T) {
|
||||
data, err := JSON("testdata/gopher-original.json")
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// t.Logf("DATA: %+v", data)
|
||||
|
||||
assert.Equal(t, "2s", data.Duration.String())
|
||||
assert.Equal(t, "2020-05-11 14:16:48 +0000 UTC", data.TakenAtLocal.String())
|
||||
assert.Equal(t, "2020-05-11 12:16:48 +0000 UTC", data.TakenAt.String())
|
||||
assert.Equal(t, "Europe/Berlin", data.TimeZone)
|
||||
assert.Equal(t, 1080, data.Width)
|
||||
assert.Equal(t, 1920, data.Height)
|
||||
assert.Equal(t, float32(52.4596), data.Lat)
|
||||
assert.Equal(t, float32(13.3218), data.Lng)
|
||||
assert.Equal(t, "", data.CameraMake)
|
||||
assert.Equal(t, "", data.CameraModel)
|
||||
assert.Equal(t, "", data.LensModel)
|
||||
})
|
||||
|
||||
t.Run("berlin-landscape.json", func(t *testing.T) {
|
||||
data, err := JSON("testdata/berlin-landscape.json")
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// t.Logf("DATA: %+v", data)
|
||||
|
||||
assert.Equal(t, "4s", data.Duration.String())
|
||||
assert.Equal(t, "2020-05-14 11:34:41 +0000 UTC", data.TakenAtLocal.String())
|
||||
assert.Equal(t, "2020-05-14 09:34:41 +0000 UTC", data.TakenAt.String())
|
||||
assert.Equal(t, "Europe/Berlin", data.TimeZone)
|
||||
assert.Equal(t, 1920, data.Width)
|
||||
assert.Equal(t, 1080, data.Height)
|
||||
assert.Equal(t, float32(52.4649), data.Lat)
|
||||
assert.Equal(t, float32(13.3148), data.Lng)
|
||||
assert.Equal(t, "", data.CameraMake)
|
||||
assert.Equal(t, "", data.CameraModel)
|
||||
assert.Equal(t, "", data.LensModel)
|
||||
})
|
||||
|
||||
t.Run("mp4.json", func(t *testing.T) {
|
||||
data, err := JSON("testdata/mp4.json")
|
||||
|
||||
|
@ -26,25 +92,6 @@ func TestJSON(t *testing.T) {
|
|||
assert.Equal(t, "", data.LensModel)
|
||||
})
|
||||
|
||||
t.Run("gopher-video.json", func(t *testing.T) {
|
||||
data, err := JSON("testdata/gopher-video.json")
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// t.Logf("DATA: %+v", data)
|
||||
|
||||
assert.Equal(t, "2s", data.Duration.String())
|
||||
assert.Equal(t, "2020-05-11 14:18:35 +0000 UTC", data.TakenAtLocal.String())
|
||||
assert.Equal(t, 270, data.Width)
|
||||
assert.Equal(t, 480, data.Height)
|
||||
assert.Equal(t, "", data.Copyright)
|
||||
assert.Equal(t, "", data.CameraMake)
|
||||
assert.Equal(t, "", data.CameraModel)
|
||||
assert.Equal(t, "", data.LensModel)
|
||||
})
|
||||
|
||||
t.Run("photoshop.json", func(t *testing.T) {
|
||||
data, err := JSON("testdata/photoshop.json")
|
||||
|
||||
|
|
75
internal/meta/testdata/berlin-landscape.json
vendored
Normal file
75
internal/meta/testdata/berlin-landscape.json
vendored
Normal file
|
@ -0,0 +1,75 @@
|
|||
[{
|
||||
"SourceFile": "/Users/michael/Downloads/20200514-113441-Schildhornstrasse-Berlin-2020-2up.mp4",
|
||||
"ExifToolVersion": 11.85,
|
||||
"FileName": "20200514-113441-Schildhornstrasse-Berlin-2020-2up.mp4",
|
||||
"Directory": "/Users/michael/Downloads",
|
||||
"FileSize": "7.1 MB",
|
||||
"FileModifyDate": "2020:05:14 14:02:42+02:00",
|
||||
"FileAccessDate": "2020:05:14 14:02:42+02:00",
|
||||
"FileInodeChangeDate": "2020:05:14 14:02:43+02:00",
|
||||
"FilePermissions": "rw-r--r--",
|
||||
"FileType": "MP4",
|
||||
"FileTypeExtension": "mp4",
|
||||
"MIMEType": "video/mp4",
|
||||
"MajorBrand": "MP4 v2 [ISO 14496-14]",
|
||||
"MinorVersion": "0.0.0",
|
||||
"CompatibleBrands": ["isom","mp42"],
|
||||
"MovieHeaderVersion": 0,
|
||||
"CreateDate": "2020:05:14 11:34:41",
|
||||
"ModifyDate": "2020:05:14 11:34:41",
|
||||
"TimeScale": 1000,
|
||||
"Duration": "4.30 s",
|
||||
"PreferredRate": 1,
|
||||
"PreferredVolume": "100.00%",
|
||||
"PreviewTime": "0 s",
|
||||
"PreviewDuration": "0 s",
|
||||
"PosterTime": "0 s",
|
||||
"SelectionTime": "0 s",
|
||||
"SelectionDuration": "0 s",
|
||||
"CurrentTime": "0 s",
|
||||
"NextTrackID": 3,
|
||||
"GPSCoordinates": "52 deg 27' 53.64\" N, 13 deg 18' 53.28\" E",
|
||||
"AndroidVersion": 10,
|
||||
"TrackHeaderVersion": 0,
|
||||
"TrackCreateDate": "2020:05:14 11:34:41",
|
||||
"TrackModifyDate": "2020:05:14 11:34:41",
|
||||
"TrackID": 1,
|
||||
"TrackDuration": "4.30 s",
|
||||
"TrackLayer": 0,
|
||||
"TrackVolume": "0.00%",
|
||||
"ImageWidth": 1920,
|
||||
"ImageHeight": 1080,
|
||||
"GraphicsMode": "srcCopy",
|
||||
"OpColor": "0 0 0",
|
||||
"CompressorID": "avc1",
|
||||
"SourceImageWidth": 1920,
|
||||
"SourceImageHeight": 1080,
|
||||
"XResolution": 72,
|
||||
"YResolution": 72,
|
||||
"BitDepth": 24,
|
||||
"PixelAspectRatio": "65536:65536",
|
||||
"ColorRepresentation": "nclx 1 1 1",
|
||||
"VideoFrameRate": 28.616,
|
||||
"MatrixStructure": "1 0 0 0 1 0 0 0 1",
|
||||
"MediaHeaderVersion": 0,
|
||||
"MediaCreateDate": "2020:05:14 11:34:41",
|
||||
"MediaModifyDate": "2020:05:14 11:34:41",
|
||||
"MediaTimeScale": 48000,
|
||||
"MediaDuration": "4.27 s",
|
||||
"HandlerType": "Audio Track",
|
||||
"HandlerDescription": "SoundHandle",
|
||||
"Balance": 0,
|
||||
"AudioFormat": "mp4a",
|
||||
"AudioChannels": 2,
|
||||
"AudioBitsPerSample": 16,
|
||||
"AudioSampleRate": 48000,
|
||||
"MediaDataSize": 6671625,
|
||||
"MediaDataOffset": 810340,
|
||||
"ImageSize": "1920x1080",
|
||||
"Megapixels": 2.1,
|
||||
"AvgBitrate": "12.4 Mbps",
|
||||
"GPSLatitude": "52 deg 27' 53.64\" N",
|
||||
"GPSLongitude": "13 deg 18' 53.28\" E",
|
||||
"Rotation": 0,
|
||||
"GPSPosition": "52 deg 27' 53.64\" N, 13 deg 18' 53.28\" E"
|
||||
}]
|
75
internal/meta/testdata/gopher-original.json
vendored
Normal file
75
internal/meta/testdata/gopher-original.json
vendored
Normal file
|
@ -0,0 +1,75 @@
|
|||
[{
|
||||
"SourceFile": "/Users/michael/Downloads/20200511-141648-Berlin-Germany-2020-3ku.mp4",
|
||||
"ExifToolVersion": 11.85,
|
||||
"FileName": "20200511-141648-Berlin-Germany-2020-3ku.mp4",
|
||||
"Directory": "/Users/michael/Downloads",
|
||||
"FileSize": "4.4 MB",
|
||||
"FileModifyDate": "2020:05:14 14:02:58+02:00",
|
||||
"FileAccessDate": "2020:05:14 14:02:58+02:00",
|
||||
"FileInodeChangeDate": "2020:05:14 14:02:58+02:00",
|
||||
"FilePermissions": "rw-r--r--",
|
||||
"FileType": "MP4",
|
||||
"FileTypeExtension": "mp4",
|
||||
"MIMEType": "video/mp4",
|
||||
"MajorBrand": "MP4 v2 [ISO 14496-14]",
|
||||
"MinorVersion": "0.0.0",
|
||||
"CompatibleBrands": ["isom","mp42"],
|
||||
"MovieHeaderVersion": 0,
|
||||
"CreateDate": "2020:05:11 14:16:48",
|
||||
"ModifyDate": "2020:05:11 14:16:48",
|
||||
"TimeScale": 1000,
|
||||
"Duration": "2.42 s",
|
||||
"PreferredRate": 1,
|
||||
"PreferredVolume": "100.00%",
|
||||
"PreviewTime": "0 s",
|
||||
"PreviewDuration": "0 s",
|
||||
"PosterTime": "0 s",
|
||||
"SelectionTime": "0 s",
|
||||
"SelectionDuration": "0 s",
|
||||
"CurrentTime": "0 s",
|
||||
"NextTrackID": 3,
|
||||
"GPSCoordinates": "52 deg 27' 34.56\" N, 13 deg 19' 18.48\" E",
|
||||
"AndroidVersion": 10,
|
||||
"TrackHeaderVersion": 0,
|
||||
"TrackCreateDate": "2020:05:11 14:16:48",
|
||||
"TrackModifyDate": "2020:05:11 14:16:48",
|
||||
"TrackID": 1,
|
||||
"TrackDuration": "2.42 s",
|
||||
"TrackLayer": 0,
|
||||
"TrackVolume": "0.00%",
|
||||
"ImageWidth": 1920,
|
||||
"ImageHeight": 1080,
|
||||
"GraphicsMode": "srcCopy",
|
||||
"OpColor": "0 0 0",
|
||||
"CompressorID": "avc1",
|
||||
"SourceImageWidth": 1920,
|
||||
"SourceImageHeight": 1080,
|
||||
"XResolution": 72,
|
||||
"YResolution": 72,
|
||||
"BitDepth": 24,
|
||||
"PixelAspectRatio": "65536:65536",
|
||||
"ColorRepresentation": "nclx 1 1 1",
|
||||
"VideoFrameRate": 28.101,
|
||||
"MatrixStructure": "1 0 0 0 1 0 0 0 1",
|
||||
"MediaHeaderVersion": 0,
|
||||
"MediaCreateDate": "2020:05:11 14:16:48",
|
||||
"MediaModifyDate": "2020:05:11 14:16:48",
|
||||
"MediaTimeScale": 48000,
|
||||
"MediaDuration": "2.41 s",
|
||||
"HandlerType": "Audio Track",
|
||||
"HandlerDescription": "SoundHandle",
|
||||
"Balance": 0,
|
||||
"AudioFormat": "mp4a",
|
||||
"AudioChannels": 2,
|
||||
"AudioBitsPerSample": 16,
|
||||
"AudioSampleRate": 48000,
|
||||
"MediaDataSize": 3818513,
|
||||
"MediaDataOffset": 810340,
|
||||
"ImageSize": "1920x1080",
|
||||
"Megapixels": 2.1,
|
||||
"AvgBitrate": "12.6 Mbps",
|
||||
"GPSLatitude": "52 deg 27' 34.56\" N",
|
||||
"GPSLongitude": "13 deg 19' 18.48\" E",
|
||||
"Rotation": 90,
|
||||
"GPSPosition": "52 deg 27' 34.56\" N, 13 deg 19' 18.48\" E"
|
||||
}]
|
Loading…
Reference in a new issue