-
-
Save sausheong/fec69f99e1f8e672fa0697ae221befb6 to your computer and use it in GitHub Desktop.
photo mosaic blog 3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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