From 4e63c622e464b6863dfec0b6c99f95833f46b12f Mon Sep 17 00:00:00 2001 From: Alexander Kiryukhin Date: Mon, 17 Aug 2020 13:42:24 +0300 Subject: Detached AsBytes method --- pkg/static/map.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'pkg/static') diff --git a/pkg/static/map.go b/pkg/static/map.go index 2597aaf..8de861f 100644 --- a/pkg/static/map.go +++ b/pkg/static/map.go @@ -26,7 +26,7 @@ const ( th = 256 ) -func GetMapImage(lat, lon float64, zoom, width, height int) ([]byte, error) { +func GetMapImage(lat, lon float64, zoom, width, height int) (image.Image, error) { x, y, dx, dy := getCoords(lat, lon, zoom) dst := imaging.New(width, height, color.NRGBA{0, 255, 0, 255}) wg := sync.WaitGroup{} @@ -57,13 +57,17 @@ func GetMapImage(lat, lon float64, zoom, width, height int) ([]byte, error) { tx := cx + i*tw - di ty := cy + j*th - dj dst = imaging.Paste(dst, img, image.Pt(tx, ty)) - }(int(i), int(j)) + }(i, j) } } wg.Wait() + return dst, nil +} + +func AsBytes(image image.Image) ([]byte,error) { out := bytes.NewBuffer([]byte{}) - if err := imaging.Encode(out, dst, imaging.PNG); err != nil { + if err := imaging.Encode(out, image, imaging.PNG); err != nil { return nil, err } return out.Bytes(), nil -- cgit v1.2.3