| 1 |
//go:build !tinygo |
| 2 |
// +build !tinygo |
| 3 |
|
| 4 |
package gfx |
| 5 |
|
| 6 |
import ( |
| 7 |
"bytes" |
| 8 |
"encoding/base64" |
| 9 |
"image" |
| 10 |
) |
| 11 |
|
| 12 |
// Base64EncodedPNG encodes the given image into |
| 13 |
// a string using base64.StdEncoding. |
| 14 |
func Base64EncodedPNG(src image.Image) string { |
| 15 |
var buf bytes.Buffer |
| 16 |
|
| 17 |
EncodePNG(&buf, src) |
| 18 |
|
| 19 |
return base64.StdEncoding.EncodeToString(buf.Bytes()) |
| 20 |
} |
| 21 |
|
| 22 |
// Base64ImgTag returns a HTML tag for an img |
| 23 |
// with its src set to a base64 encoded PNG. |
| 24 |
func Base64ImgTag(src image.Image) string { |
| 25 |
return `<img src="data:image/png;base64,` + Base64EncodedPNG(src) + `">` |
| 26 |
} |