-
-
Save sausheong/f3443630fffbf4679713c44b95624ec5 to your computer and use it in GitHub Desktop.
photo mosaic blog 11
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
| for y := bounds.Min.Y; y < bounds.Max.Y; y = y + tileSize { | |
| for x := bounds.Min.X; x < bounds.Max.X; x = x + tileSize { | |
| // use the top left most pixel color as the average color | |
| r, g, b, _ := original.At(x, y).RGBA() | |
| color := [3]float64{float64(r), float64(g), float64(b)} | |
| // get the closest tile from the tiles DB | |
| nearest := nearest(color, &db) | |
| file, err := os.Open(nearest) | |
| if err == nil { | |
| img, _, err := image.Decode(file) | |
| if err == nil { | |
| // resize the tile to the correct size | |
| t := resize(img, tileSize) | |
| tile := t.SubImage(t.Bounds()) | |
| tileBounds := image.Rect(x, y, x+tileSize, y+tileSize) | |
| // draw the tile into the mosaic | |
| draw.Draw(newimage, tileBounds, tile, sp, draw.Src) | |
| } else { | |
| fmt.Println("error:", err, nearest) | |
| } | |
| } else { | |
| fmt.Println("error:", nearest) | |
| } | |
| file.Close() | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment