-
Notifications
You must be signed in to change notification settings - Fork 1
/
imagedir.go
58 lines (51 loc) · 1.29 KB
/
imagedir.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
package main
import (
"fmt"
"log"
"os"
"path/filepath"
"strings"
"github.com/xiam/exif"
)
// processDir walks a directory to find images to process
func processDir(dir string) {
err := filepath.WalkDir(dir, func(path string, d os.DirEntry, err error) error {
if strings.HasPrefix(filepath.Base(path), ".") {
return nil
}
if filepath.Ext(path) == ".jpg" || filepath.Ext(path) == ".JPG" {
tags := processImage(path)
fmt.Println(path, tags)
return nil
}
return err
})
if err != nil {
log.Fatalf("Unable to process directory: %s\n%s\n", dir, err)
}
}
// processImage obtains address data for the GPS location
func processImage(path string) []string {
data, err := exif.Read(path)
if err != nil {
log.Panic(err)
}
coords := parseCoord(
data.Tags["Latitude"],
data.Tags["North or South Latitude"],
data.Tags["Longitude"],
data.Tags["East or West Longitude"],
)
loc := decodeLocation(apikey, coords.Latitude, coords.Longitude)
var tags []string
for _, item := range loc.Items {
if item.Address.District != item.Address.City {
tags = append(tags, item.Address.District)
}
tags = append(tags, item.Address.City)
tags = append(tags, item.Address.County)
tags = append(tags, item.Address.State)
tags = append(tags, item.Address.CountryName)
}
return tags
}