-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimage.go
64 lines (50 loc) · 1.14 KB
/
image.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
package main
import (
"log"
"os"
"path"
"strings"
"github.com/rwcarlsen/goexif/exif"
)
type ImageObj struct {
*FileObj
}
func (i *ImageObj) getTags() (*exif.Exif, error) {
fp, err := os.Open(i.filename)
if err != nil {
// Issue opening the file
return nil, err
}
tags, err := exif.Decode(fp)
if err != nil {
return nil, err
}
return tags, nil
}
// Parse the date string from an exif tag and return the year, month and day
// in the format YYYYMMDD.
func (i *ImageObj) getDatePath(tags *exif.Exif) (string, error) {
value, err := tags.Get(exif.DateTimeOriginal)
if err != nil {
return "", err
}
dateStr, err := value.StringVal()
if err != nil {
return "", err
}
dateSlice := strings.SplitN(dateStr, ":", 3)
return path.Join(dateSlice[0], dateSlice[1]), nil
}
func (i *ImageObj) GetDestination() (string, error) {
log.Println("Processing file: ", i.filename)
// Set the tags on the struct
tags, err := i.getTags()
if err != nil {
return path.Join(i.destpath, "image"), nil
}
date, err := i.getDatePath(tags)
if err != nil {
return path.Join(i.destpath, "image"), nil
}
return path.Join(i.destpath, date), nil
}