Exif: Shorten exposure time #227

Signed-off-by: Michael Mayer <michael@liquidbytes.net>
This commit is contained in:
Michael Mayer 2020-04-26 12:17:49 +02:00
parent 3edf30ab3a
commit 4a6f1700c1
2 changed files with 13 additions and 0 deletions

View file

@ -157,6 +157,15 @@ func Exif(filename string) (data Data, err error) {
}
if value, ok := tags["ExposureTime"]; ok {
if n := strings.Split(value, "/"); len(n) == 2 {
if n[0] != "1" && len(n[0]) < len(n[1]) {
n0, _ := strconv.ParseUint(n[0], 10, 64)
if n1, err := strconv.ParseUint(n[1], 10, 64); err == nil && n0 > 0 && n1 > 0 {
value = fmt.Sprintf("1/%d", n1 / n0)
}
}
}
data.Exposure = value
}

View file

@ -24,6 +24,7 @@ func TestExif(t *testing.T) {
assert.Equal(t, float32(52.45969), data.Lat)
assert.Equal(t, float32(13.321832), data.Lng)
assert.Equal(t, 0, data.Altitude)
assert.Equal(t, "1/50", data.Exposure)
assert.Equal(t, "HUAWEI", data.CameraMake)
assert.Equal(t, "ELE-L29", data.CameraModel)
assert.Equal(t, "", data.CameraOwner)
@ -56,6 +57,7 @@ func TestExif(t *testing.T) {
assert.Equal(t, float32(51.254852), data.Lat)
assert.Equal(t, float32(7.389468), data.Lng)
assert.Equal(t, 0, data.Altitude)
assert.Equal(t, "1/125", data.Exposure)
assert.Equal(t, "Canon", data.CameraMake)
assert.Equal(t, "Canon EOS 50D", data.CameraModel)
assert.Equal(t, "Thomas Meyer-Boudnik", data.CameraOwner)
@ -84,6 +86,7 @@ func TestExif(t *testing.T) {
assert.Equal(t, 3840, data.Width)
assert.Equal(t, float32(0), data.Lng)
assert.Equal(t, 0, data.Altitude)
assert.Equal(t, "1/2462", data.Exposure)
assert.Equal(t, "GoPro", data.CameraMake)
assert.Equal(t, "HD2", data.CameraModel)
assert.Equal(t, "", data.CameraOwner)
@ -110,6 +113,7 @@ func TestExif(t *testing.T) {
assert.Equal(t, float32(34.79745), data.Lat)
assert.Equal(t, float32(134.76463), data.Lng)
assert.Equal(t, 0, data.Altitude)
assert.Equal(t, "1/4000", data.Exposure)
assert.Equal(t, "Apple", data.CameraMake)
assert.Equal(t, "iPhone 7", data.CameraModel)
assert.Equal(t, 74, data.FocalLength)