示例#1
0
文件: draw.go 项目: delfvad/hi
func mustParseHex(s string) colorful.Color {
	c, err := colorful.Hex(s)
	if err != nil {
		panic("MustParseHex: " + err.Error())
	}

	return c
}
示例#2
0
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
}