Skip to content

Instantly share code, notes, and snippets.

@sausheong
Created December 28, 2019 12:38
Show Gist options
  • Select an option

  • Save sausheong/fec69f99e1f8e672fa0697ae221befb6 to your computer and use it in GitHub Desktop.

Select an option

Save sausheong/fec69f99e1f8e672fa0697ae221befb6 to your computer and use it in GitHub Desktop.
photo mosaic blog 3
// populate a tiles database in memory
func tilesDB() map[string][3]float64 {
fmt.Println("Start populating tiles db ...")
db := make(map[string][3]float64)
files, _ := ioutil.ReadDir("tiles")
for _, f := range files {
name := "tiles/" + f.Name()
file, err := os.Open(name)
if err == nil {
img, _, err := image.Decode(file)
if err == nil {
db[name] = averageColor(img)
} else {
fmt.Println(":", err, name)
}
} else {
fmt.Println("cannot open file", name, err)
}
file.Close()
}
fmt.Println("Finished populating tiles db.")
return db
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment