[Golang] 纯文本查看 复制代码
func geetest(base64 string) (string, error) {
array := []int{39, 38, 48, 49, 41, 40, 46, 47, 35, 34, 50, 51, 33, 32, 28, 29, 27, 26, 36, 37, 31, 30, 44, 45, 43, 42, 12, 13, 23, 22, 14, 15, 21, 20, 8, 9, 25, 24, 6, 7, 3, 2, 0, 1, 11, 10, 4, 5, 19, 18, 16, 17}
originalImage, err := base64toimage(base64)
fmt.Println(err)
if err != nil {
// 处理解码错误
return "", errors.New("error")
}
convertedImage := image.NewRGBA(image.Rect(0, 0, 312, 160))
//
for i := 0; i < len(array); i++ {
c := array%26*12 + 1
fmt.Println(c)
u := 0
db := 0
if array > 25 {
u = 80
} else {
u = 0
}
if i > 25 {
db = 80
} else {
db = 0
}
copyImage(convertedImage, originalImage, i%26*10, db, c, u, 10, 80)
// 使用 array 进行操作
}
base64Result := imagetobase64(convertedImage)
return base64Result, nil
}
func copyImage(dest *image.RGBA, src image.Image, dx, dy, sx, sy, width, height int) {
for y := 0; y < height; y++ {
for x := 0; x < width; x++ {
convertedPixel := color.RGBAModel.Convert(src.At(x+sx, y+sy))
dest.SetRGBA(x+dx, y+dy, convertedPixel.(color.RGBA))
}
}
}