-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathbase64.go
More file actions
26 lines (20 loc) · 550 Bytes
/
base64.go
File metadata and controls
26 lines (20 loc) · 550 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
//go:build !tinygo
// +build !tinygo
package gfx
import (
"bytes"
"encoding/base64"
"image"
)
// Base64EncodedPNG encodes the given image into
// a string using base64.StdEncoding.
func Base64EncodedPNG(src image.Image) string {
var buf bytes.Buffer
EncodePNG(&buf, src)
return base64.StdEncoding.EncodeToString(buf.Bytes())
}
// Base64ImgTag returns a HTML tag for an img
// with its src set to a base64 encoded PNG.
func Base64ImgTag(src image.Image) string {
return `<img src="data:image/png;base64,` + Base64EncodedPNG(src) + `">`
}