func mustParseHex(s string) colorful.Color { c, err := colorful.Hex(s) if err != nil { panic("MustParseHex: " + err.Error()) } return c }
func Generate(url, fcolor, bcolor, size, logo string) []byte { var fc, bc color.Color var bcFmt = []string{"#", "", "", "", "", "", ""} var qrSize = 300 if size != "" { qrSize, _ = strconv.Atoi(size) } if fcolor != "" { // println(strings.Join([]string{"#","","","","","",""}, "a")) fc, _ = colorful.Hex(strings.Join(bcFmt, fcolor)) } else { fc = color.Black } if bcolor != "" { println(bcolor) bc, _ = colorful.Hex(strings.Join(bcFmt, bcolor)) } else { bc = color.White } q, e := qrcode.New(url, qrcode.High) if e != nil { println(e.Error()) return nil } // println(fc) // println(q) q.ForegroundColor = fc q.BackgroundColor = bc qrPng, _ := q.PNG(qrSize) qrPng = DrawLogo(qrPng, logo, bc) return qrPng }