From 9674796f0a5bcc11f5bfd5aaa19947cda4e42f26 Mon Sep 17 00:00:00 2001 From: coward Date: Tue, 24 Dec 2024 16:37:45 +0800 Subject: [PATCH] =?UTF-8?q?:art:=E5=88=A0=E9=99=A4=E6=B2=A1=E5=BF=85?= =?UTF-8?q?=E8=A6=81=E7=9A=84=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/qr_code.go | 43 ------------------------------------------- 1 file changed, 43 deletions(-) diff --git a/utils/qr_code.go b/utils/qr_code.go index c17769b..5521854 100644 --- a/utils/qr_code.go +++ b/utils/qr_code.go @@ -4,7 +4,6 @@ import ( "encoding/base64" "gitee.ltd/lxh/logger/log" "github.com/skip2/go-qrcode" - "image/color" ) type qrCode struct{} @@ -37,45 +36,3 @@ func (qr qrCode) GenerateQrCodeBase64(content []byte, size int) (imgStr string, imgStr = "data:image/png;base64," + base64.StdEncoding.EncodeToString(png) return } - -// GenerateQrCodeASCII -// @description: 生成二维码 -// @receiver qr -// @param content -// @param size -// @return imgStr -// @return err -func (qr qrCode) GenerateQrCodeASCII(content []byte) (str string, err error) { - q, err := qrcode.New(string(content), qrcode.Highest) - if err != nil { - log.Errorf("初始化二维码对象失败: %v", err.Error()) - return - } - - // 设置二维码的尺寸,这里是 16 的倍数 - size := 16 - img := q.Image(size) - - isBlock := func(c color.Color) bool { - r, g, b, _ := c.RGBA() - // 转换到 0-255 范围,并判断是否接近黑色 - return r < 5000 && g < 5000 && b < 5000 - } - - for y := 0; y < img.Bounds().Dy(); y += 16 { - for x := 0; x < img.Bounds().Dx(); x++ { - // 获取当前像素的颜色 - color := img.At(x, y) - - // 判断像素是否接近黑色,黑色输出为 '██',白色输出为空格 - if isBlock(color) { - str += "██" // 黑色模块,输出方块字符 - } else { - str += " " // 白色模块,输出空格 - } - } - str += "\n" - } - - return str, nil -}