Loading app-backend/main.go +3 −5 Original line number Diff line number Diff line Loading @@ -19,11 +19,9 @@ func main() { r.HandleFunc("/checkerboard", checkerboard.Checkerboard) r.HandleFunc("/squares/?", squares.Random) r.HandleFunc("/squares/random/?", squares.Random) r.HandleFunc("/squares/random/:colorId", squares.RandomColor) r.HandleFunc("/squares", squares.Random) r.HandleFunc("/squares/random", squares.Random) r.HandleFunc("/squares/:key", squares.Square) //cached r.HandleFunc("/squares/:colorId/:key", squares.Color) // cached r.HandleFunc("/isogrids/skeleton", isogrids.Skeleton) r.HandleFunc("/isogrids/:key", isogrids.Isogrids) Loading app/partials/marketing/example.html +1 −1 Original line number Diff line number Diff line Loading @@ -6,7 +6,7 @@ <img class="featurette-image img-responsive img-thumbnail" src="/checkerboard" alt="grid image"> </div> <div class="col-md-3"> <img class="featurette-image img-responsive img-thumbnail" src="/squares/random/1?fmt=svg" alt="random black an white avatar"> <img class="featurette-image img-responsive img-thumbnail" src="/squares/random?theme=summerwarmth&fmt=svg" alt="random black an white avatar"> </div> <div class="col-md-3"> <img class="featurette-image img-responsive img-thumbnail" src="/squares/tinygraphs" alt="consistent square black and white avatar"> Loading app/partials/marketing/specs.html +3 −3 Original line number Diff line number Diff line Loading @@ -7,21 +7,21 @@ <div class="row"> <div class="col-lg-4"> <img class="img-circle img-thumbnail" src="/squares/random/2?fmt=svg&size=140" alt="square grid example"> <img class="img-circle img-thumbnail" src="/squares/random/?theme=heatwave&fmt=svg&size=140" alt="square grid example"> <h2>Squares</h2> <p>This is a simple and really ressoursefull pattern that generates a <b>consistent</b> 6X6 grid image with squares of two colors.</p> <p><a class="btn btn-default" href="#" role="button">View details »</a></p> </div><!-- /.col-lg-4 --> <div class="col-lg-4"> <img class="img-circle img-thumbnail" src="/squares/random/4?fmt=svg&size=140" alt="isometric grid example"> <img class="img-circle img-thumbnail" src="/squares/random?theme=daisygarden&fmt=svg&size=140" alt="isometric grid example"> <h2>Isometric grids</h2> <p>This pattern gives you a lot of flexibility when generating the avatars.</p> <p><a class="btn btn-default" href="#" role="button">View details »</a></p> </div><!-- /.col-lg-4 --> <div class="col-lg-4"> <img class="img-circle img-thumbnail" src="/squares/random/6?fmt=svg&size=140" alt="..."> <img class="img-circle img-thumbnail" src="/squares/random?theme=seascape&fmt=svg&size=140" alt="..."> <h2>something else..</h2> <p>under construction...</p> <p><a class="btn btn-default" href="#" role="button">View details »</a></p> Loading controllers/squares/random.go +14 −47 Original line number Diff line number Diff line Loading @@ -3,11 +3,8 @@ package squares import ( "image" "image/color" "log" "net/http" "strconv" "github.com/taironas/route" "github.com/taironas/tinygraphs/colors" "github.com/taironas/tinygraphs/draw" "github.com/taironas/tinygraphs/extract" Loading @@ -19,61 +16,31 @@ import ( // generates a black and white grid random image. func Random(w http.ResponseWriter, r *http.Request) { size := extract.Size(r) colorMap := colors.MapOfColorPatterns() bg, err1 := extract.Background(r) if err1 != nil { bg = colorMap[0][0] } fg, err2 := extract.Foreground(r) if err2 != nil { fg = colorMap[0][1] } if f := extract.Format(r); f == format.JPEG { m := image.NewRGBA(image.Rect(0, 0, size, size)) draw.RandomGrid6X6(m, bg, fg) var img image.Image = m write.ImageJPEG(w, &img) } else if f == format.SVG { write.ImageSVG(w) draw.RandomGrid6X6SVG(w, bg, fg, size) } } theme := extract.Theme(r) colorMap := colors.MapOfColorThemes() // handler for "/squares/random/:colorId" // generates a grid random image with a specific color based on the colorMap func RandomColor(w http.ResponseWriter, r *http.Request) { var bg, fg color.RGBA var err error var id string if id, err = route.Context.Get(r, "colorId"); err != nil { log.Println("Unable to get 'colorId' value: ", err) id = "0" } var colorId int64 if colorId, err = strconv.ParseInt(id, 0, 64); err != nil { log.Printf("error when extracting permalink id: %v", err) colorId = 0 } size := extract.Size(r) colorMap := colors.MapOfColorPatterns() var c1, c2 color.RGBA if val, ok := colorMap[int(colorId)]; ok { c1 = val[0] c2 = val[1] if val, ok := colorMap[theme]; ok { bg = val[0] fg = val[1] } else { c1 = colorMap[0][0] c2 = colorMap[0][1] if bg, err = extract.Background(r); err != nil { bg = colorMap["base"][0] } if fg, err = extract.Foreground(r); err != nil { fg = colorMap["base"][1] } } if f := extract.Format(r); f == format.JPEG { m := image.NewRGBA(image.Rect(0, 0, size, size)) draw.RandomGrid6X6(m, c1, c2) draw.RandomGrid6X6(m, bg, fg) var img image.Image = m write.ImageJPEG(w, &img) } else if f == format.SVG { write.ImageSVG(w) draw.RandomGrid6X6SVG(w, c1, c2, size) draw.RandomGrid6X6SVG(w, bg, fg, size) } } controllers/squares/square.go +14 −61 Original line number Diff line number Diff line Loading @@ -8,11 +8,10 @@ import ( "io" "log" "net/http" "strconv" "strings" "github.com/taironas/route" tgColors "github.com/taironas/tinygraphs/colors" "github.com/taironas/tinygraphs/colors" "github.com/taironas/tinygraphs/draw" "github.com/taironas/tinygraphs/extract" "github.com/taironas/tinygraphs/format" Loading @@ -32,12 +31,13 @@ func Square(w http.ResponseWriter, r *http.Request) { log.Println("Unable to get 'key' value: ", err) key = "" } theme := extract.Theme(r) h := md5.New() io.WriteString(h, key) key = fmt.Sprintf("%x", h.Sum(nil)[:]) e := `"` + key + `"` e := `"` + theme + key + `"` w.Header().Set("Etag", e) w.Header().Set("Cache-Control", "max-age=2592000") // 30 days Loading @@ -48,14 +48,18 @@ func Square(w http.ResponseWriter, r *http.Request) { } } colorMap := tgColors.MapOfColorPatterns() colorMap := colors.MapOfColorThemes() var bg, fg color.RGBA if val, ok := colorMap[theme]; ok { bg = val[0] fg = val[1] } else { if bg, err = extract.Background(r); err != nil { bg = colorMap[0][0] bg = colorMap["base"][0] } if fg, err = extract.Foreground(r); err != nil { fg = colorMap[0][1] fg = colorMap["base"][1] } } size := extract.Size(r) Loading @@ -69,54 +73,3 @@ func Square(w http.ResponseWriter, r *http.Request) { draw.SquaresSVG(w, key, bg, fg, size) } } // Color is the handler for /square/:colorId/:key // build a 6x6 grid with alternate colors based on the number passed in the url func Color(w http.ResponseWriter, r *http.Request) { var err error var id string if id, err = route.Context.Get(r, "colorId"); err != nil { log.Println("Unable to get 'colorId' value: ", err) id = "0" } var colorId int64 if colorId, err = strconv.ParseInt(id, 0, 64); err != nil { colorId = 0 } var key string if key, err = route.Context.Get(r, "key"); err != nil { log.Println("Unable to get 'key' value: ", err) key = "" } h := md5.New() io.WriteString(h, key) key = fmt.Sprintf("%x", h.Sum(nil)[:]) strId := strconv.FormatInt(colorId, 10) e := `"` + key + `-` + strId + `"` w.Header().Set("Etag", e) w.Header().Set("Cache-Control", "max-age=2592000") // 30 days if match := r.Header.Get("If-None-Match"); match != "" { if strings.Contains(match, e) { w.WriteHeader(http.StatusNotModified) return } } size := extract.Size(r) colorMap := tgColors.MapOfColorPatterns() if f := extract.Format(r); f == format.JPEG { m := image.NewRGBA(image.Rect(0, 0, size, size)) draw.Squares(m, key, colorMap[int(colorId)][0], colorMap[int(colorId)][1]) var img image.Image = m write.ImageJPEG(w, &img) } else if f == format.SVG { write.ImageSVG(w) draw.SquaresSVG(w, key, colorMap[int(colorId)][0], colorMap[int(colorId)][1], size) } } Loading
app-backend/main.go +3 −5 Original line number Diff line number Diff line Loading @@ -19,11 +19,9 @@ func main() { r.HandleFunc("/checkerboard", checkerboard.Checkerboard) r.HandleFunc("/squares/?", squares.Random) r.HandleFunc("/squares/random/?", squares.Random) r.HandleFunc("/squares/random/:colorId", squares.RandomColor) r.HandleFunc("/squares", squares.Random) r.HandleFunc("/squares/random", squares.Random) r.HandleFunc("/squares/:key", squares.Square) //cached r.HandleFunc("/squares/:colorId/:key", squares.Color) // cached r.HandleFunc("/isogrids/skeleton", isogrids.Skeleton) r.HandleFunc("/isogrids/:key", isogrids.Isogrids) Loading
app/partials/marketing/example.html +1 −1 Original line number Diff line number Diff line Loading @@ -6,7 +6,7 @@ <img class="featurette-image img-responsive img-thumbnail" src="/checkerboard" alt="grid image"> </div> <div class="col-md-3"> <img class="featurette-image img-responsive img-thumbnail" src="/squares/random/1?fmt=svg" alt="random black an white avatar"> <img class="featurette-image img-responsive img-thumbnail" src="/squares/random?theme=summerwarmth&fmt=svg" alt="random black an white avatar"> </div> <div class="col-md-3"> <img class="featurette-image img-responsive img-thumbnail" src="/squares/tinygraphs" alt="consistent square black and white avatar"> Loading
app/partials/marketing/specs.html +3 −3 Original line number Diff line number Diff line Loading @@ -7,21 +7,21 @@ <div class="row"> <div class="col-lg-4"> <img class="img-circle img-thumbnail" src="/squares/random/2?fmt=svg&size=140" alt="square grid example"> <img class="img-circle img-thumbnail" src="/squares/random/?theme=heatwave&fmt=svg&size=140" alt="square grid example"> <h2>Squares</h2> <p>This is a simple and really ressoursefull pattern that generates a <b>consistent</b> 6X6 grid image with squares of two colors.</p> <p><a class="btn btn-default" href="#" role="button">View details »</a></p> </div><!-- /.col-lg-4 --> <div class="col-lg-4"> <img class="img-circle img-thumbnail" src="/squares/random/4?fmt=svg&size=140" alt="isometric grid example"> <img class="img-circle img-thumbnail" src="/squares/random?theme=daisygarden&fmt=svg&size=140" alt="isometric grid example"> <h2>Isometric grids</h2> <p>This pattern gives you a lot of flexibility when generating the avatars.</p> <p><a class="btn btn-default" href="#" role="button">View details »</a></p> </div><!-- /.col-lg-4 --> <div class="col-lg-4"> <img class="img-circle img-thumbnail" src="/squares/random/6?fmt=svg&size=140" alt="..."> <img class="img-circle img-thumbnail" src="/squares/random?theme=seascape&fmt=svg&size=140" alt="..."> <h2>something else..</h2> <p>under construction...</p> <p><a class="btn btn-default" href="#" role="button">View details »</a></p> Loading
controllers/squares/random.go +14 −47 Original line number Diff line number Diff line Loading @@ -3,11 +3,8 @@ package squares import ( "image" "image/color" "log" "net/http" "strconv" "github.com/taironas/route" "github.com/taironas/tinygraphs/colors" "github.com/taironas/tinygraphs/draw" "github.com/taironas/tinygraphs/extract" Loading @@ -19,61 +16,31 @@ import ( // generates a black and white grid random image. func Random(w http.ResponseWriter, r *http.Request) { size := extract.Size(r) colorMap := colors.MapOfColorPatterns() bg, err1 := extract.Background(r) if err1 != nil { bg = colorMap[0][0] } fg, err2 := extract.Foreground(r) if err2 != nil { fg = colorMap[0][1] } if f := extract.Format(r); f == format.JPEG { m := image.NewRGBA(image.Rect(0, 0, size, size)) draw.RandomGrid6X6(m, bg, fg) var img image.Image = m write.ImageJPEG(w, &img) } else if f == format.SVG { write.ImageSVG(w) draw.RandomGrid6X6SVG(w, bg, fg, size) } } theme := extract.Theme(r) colorMap := colors.MapOfColorThemes() // handler for "/squares/random/:colorId" // generates a grid random image with a specific color based on the colorMap func RandomColor(w http.ResponseWriter, r *http.Request) { var bg, fg color.RGBA var err error var id string if id, err = route.Context.Get(r, "colorId"); err != nil { log.Println("Unable to get 'colorId' value: ", err) id = "0" } var colorId int64 if colorId, err = strconv.ParseInt(id, 0, 64); err != nil { log.Printf("error when extracting permalink id: %v", err) colorId = 0 } size := extract.Size(r) colorMap := colors.MapOfColorPatterns() var c1, c2 color.RGBA if val, ok := colorMap[int(colorId)]; ok { c1 = val[0] c2 = val[1] if val, ok := colorMap[theme]; ok { bg = val[0] fg = val[1] } else { c1 = colorMap[0][0] c2 = colorMap[0][1] if bg, err = extract.Background(r); err != nil { bg = colorMap["base"][0] } if fg, err = extract.Foreground(r); err != nil { fg = colorMap["base"][1] } } if f := extract.Format(r); f == format.JPEG { m := image.NewRGBA(image.Rect(0, 0, size, size)) draw.RandomGrid6X6(m, c1, c2) draw.RandomGrid6X6(m, bg, fg) var img image.Image = m write.ImageJPEG(w, &img) } else if f == format.SVG { write.ImageSVG(w) draw.RandomGrid6X6SVG(w, c1, c2, size) draw.RandomGrid6X6SVG(w, bg, fg, size) } }
controllers/squares/square.go +14 −61 Original line number Diff line number Diff line Loading @@ -8,11 +8,10 @@ import ( "io" "log" "net/http" "strconv" "strings" "github.com/taironas/route" tgColors "github.com/taironas/tinygraphs/colors" "github.com/taironas/tinygraphs/colors" "github.com/taironas/tinygraphs/draw" "github.com/taironas/tinygraphs/extract" "github.com/taironas/tinygraphs/format" Loading @@ -32,12 +31,13 @@ func Square(w http.ResponseWriter, r *http.Request) { log.Println("Unable to get 'key' value: ", err) key = "" } theme := extract.Theme(r) h := md5.New() io.WriteString(h, key) key = fmt.Sprintf("%x", h.Sum(nil)[:]) e := `"` + key + `"` e := `"` + theme + key + `"` w.Header().Set("Etag", e) w.Header().Set("Cache-Control", "max-age=2592000") // 30 days Loading @@ -48,14 +48,18 @@ func Square(w http.ResponseWriter, r *http.Request) { } } colorMap := tgColors.MapOfColorPatterns() colorMap := colors.MapOfColorThemes() var bg, fg color.RGBA if val, ok := colorMap[theme]; ok { bg = val[0] fg = val[1] } else { if bg, err = extract.Background(r); err != nil { bg = colorMap[0][0] bg = colorMap["base"][0] } if fg, err = extract.Foreground(r); err != nil { fg = colorMap[0][1] fg = colorMap["base"][1] } } size := extract.Size(r) Loading @@ -69,54 +73,3 @@ func Square(w http.ResponseWriter, r *http.Request) { draw.SquaresSVG(w, key, bg, fg, size) } } // Color is the handler for /square/:colorId/:key // build a 6x6 grid with alternate colors based on the number passed in the url func Color(w http.ResponseWriter, r *http.Request) { var err error var id string if id, err = route.Context.Get(r, "colorId"); err != nil { log.Println("Unable to get 'colorId' value: ", err) id = "0" } var colorId int64 if colorId, err = strconv.ParseInt(id, 0, 64); err != nil { colorId = 0 } var key string if key, err = route.Context.Get(r, "key"); err != nil { log.Println("Unable to get 'key' value: ", err) key = "" } h := md5.New() io.WriteString(h, key) key = fmt.Sprintf("%x", h.Sum(nil)[:]) strId := strconv.FormatInt(colorId, 10) e := `"` + key + `-` + strId + `"` w.Header().Set("Etag", e) w.Header().Set("Cache-Control", "max-age=2592000") // 30 days if match := r.Header.Get("If-None-Match"); match != "" { if strings.Contains(match, e) { w.WriteHeader(http.StatusNotModified) return } } size := extract.Size(r) colorMap := tgColors.MapOfColorPatterns() if f := extract.Format(r); f == format.JPEG { m := image.NewRGBA(image.Rect(0, 0, size, size)) draw.Squares(m, key, colorMap[int(colorId)][0], colorMap[int(colorId)][1]) var img image.Image = m write.ImageJPEG(w, &img) } else if f == format.SVG { write.ImageSVG(w) draw.SquaresSVG(w, key, colorMap[int(colorId)][0], colorMap[int(colorId)][1], size) } }