User messages management + png contactcard to protobuf

This commit is contained in:
ycc
2022-09-19 14:09:32 +02:00
parent 3ef38350c6
commit 73ddfdcaa6
3 changed files with 69 additions and 28 deletions

View File

@ -12,6 +12,7 @@ import (
"github.com/makiuchi-d/gozxing"
"github.com/makiuchi-d/gozxing/qrcode"
"google.golang.org/protobuf/proto"
)
func ServerFromUrl(url string) *Server {
@ -26,10 +27,12 @@ func (Contact *ContactCard) AddUrls(urls []string) {
}
}
func (Contact *ContactCard) WritePng(filename string) {
jsonContact, _ := json.Marshal(Contact)
//imgdata := base64.StdEncoding.EncodeToString(jsonContact)
size := int(math.Sqrt(float64(len(jsonContact))/3)) + 1
func (contact *ContactCard) WritePng(filename string) {
out, err := proto.Marshal(contact)
if err != nil {
println(err)
}
size := int(math.Sqrt(float64(len(out))/3)) + 1
println(size)
// Create a colored i mage of the given width and height.
@ -37,9 +40,9 @@ func (Contact *ContactCard) WritePng(filename string) {
for y := 0; y < size; y++ {
for x := 0; x < size*3; x = x + 3 {
p1 := uint8(jsonContact[x+y])
p2 := uint8(jsonContact[x+y+1])
p3 := uint8(jsonContact[x+y+2])
p1 := uint8(out[x+y])
p2 := uint8(out[x+y+1])
p3 := uint8(out[x+y+2])
img.Set(x/3, y, color.NRGBA{
R: p1,
G: p2,