From d475ea5083f0560568ce51d1ad3359d24078e9c2 Mon Sep 17 00:00:00 2001 From: steven Date: Sun, 3 Mar 2019 13:46:33 -0700 Subject: [PATCH] add labels to images --- render.go | 19 +++++++++++++++++++ web.go | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/render.go b/render.go index 1a54be8..213ea66 100644 --- a/render.go +++ b/render.go @@ -1,6 +1,7 @@ package main import ( + "fmt" "image" "image/color" "image/png" @@ -14,6 +15,9 @@ import ( "sync" "deadbeef.codes/steven/mandelmapper/palette" + "golang.org/x/image/font" + "golang.org/x/image/font/basicfont" + "golang.org/x/image/math/fixed" ) const ( @@ -167,6 +171,8 @@ func renderTile(w http.ResponseWriter, r *http.Request) { } } wg.Wait() + + addLabel(img, 10, 10, fmt.Sprintf("%d/%d/%d", tileZoom, tileX, tileY)) w.Header().Set("Content-Type", "image/png") png.Encode(w, img) } @@ -181,3 +187,16 @@ func mandelbrot(c complex128) uint16 { } return Iterations } + +func addLabel(img *image.RGBA, x, y int, label string) { + col := color.RGBA{200, 100, 0, 255} + point := fixed.Point26_6{fixed.Int26_6(x * 64), fixed.Int26_6(y * 64)} + + d := &font.Drawer{ + Dst: img, + Src: image.NewUniform(col), + Face: basicfont.Face7x13, + Dot: point, + } + d.DrawString(label) +} diff --git a/web.go b/web.go index ffbd159..0f62577 100644 --- a/web.go +++ b/web.go @@ -18,7 +18,7 @@ func init() { MandelMapper - +