-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathexif.go
122 lines (104 loc) · 2.3 KB
/
exif.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package filetrove
import (
"github.com/rwcarlsen/goexif/exif"
"os"
)
type ExifParsed struct {
ExifVersion string
DateTime string
DateTimeOrig string
Artist string
Copyright string
Make string
Software string
XPTitle string
XPComment string
XPAuthor string
XPKeywords string
XPSubject string
}
func ExifDecode(fileName string) (ExifParsed, error) {
var ep ExifParsed
fd, err := os.Open(fileName)
if err != nil {
return ep, err
}
imgdecoded, err := exif.Decode(fd)
if err != nil {
return ep, err
}
exVersion, err := imgdecoded.Get(exif.ExifVersion)
if err != nil {
ep.ExifVersion = "not found"
} else {
ep.ExifVersion = exVersion.String()
}
exDate, err := imgdecoded.Get(exif.DateTime)
if err != nil {
ep.DateTime = "not found"
} else {
ep.DateTime = exDate.String()
}
exDateOrig, err := imgdecoded.Get(exif.DateTimeOriginal)
if err != nil {
ep.DateTimeOrig = "not found"
} else {
ep.DateTimeOrig = exDateOrig.String()
}
exArtist, err := imgdecoded.Get(exif.Artist)
if err != nil {
ep.Artist = "not found"
} else {
ep.Artist = exArtist.String()
}
exCopyright, err := imgdecoded.Get(exif.Copyright)
if err != nil {
ep.Copyright = "not found"
} else {
ep.Copyright = exCopyright.String()
}
exMake, err := imgdecoded.Get(exif.Make)
if err != nil {
ep.Make = "not found"
} else {
ep.Make = exMake.String()
}
exSoftware, err := imgdecoded.Get(exif.Software)
if err != nil {
ep.Software = "not found"
} else {
ep.Software = exSoftware.String()
}
// Microsoft part
exxptitle, err := imgdecoded.Get(exif.XPTitle)
if err != nil {
ep.XPTitle = "not found"
} else {
ep.XPTitle = exxptitle.String()
}
exxpcomment, err := imgdecoded.Get(exif.XPComment)
if err != nil {
ep.XPComment = "not found"
} else {
ep.XPComment = exxpcomment.String()
}
exxpauthor, err := imgdecoded.Get(exif.XPAuthor)
if err != nil {
ep.XPAuthor = "not found"
} else {
ep.XPAuthor = exxpauthor.String()
}
exxpkeywords, err := imgdecoded.Get(exif.XPKeywords)
if err != nil {
ep.XPKeywords = "not found"
} else {
ep.XPKeywords = exxpkeywords.String()
}
exxpsubject, err := imgdecoded.Get(exif.XPSubject)
if err != nil {
ep.XPSubject = "not found"
} else {
ep.XPSubject = exxpsubject.String()
}
return ep, nil
}