mirror of
https://github.com/wenlng/go-captcha.git
synced 2025-12-24 12:38:00 +08:00
27 lines
490 B
Go
27 lines
490 B
Go
package tests
|
|
|
|
import (
|
|
"image"
|
|
"io/ioutil"
|
|
|
|
"github.com/golang/freetype"
|
|
"github.com/golang/freetype/truetype"
|
|
"github.com/wenlng/go-captcha/v2/base/codec"
|
|
)
|
|
|
|
func loadPng(p string) (image.Image, error) {
|
|
imgBytes, err := ioutil.ReadFile(p)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return codec.DecodeByteToPng(imgBytes)
|
|
}
|
|
|
|
func loadFont(p string) (*truetype.Font, error) {
|
|
fontBytes, err := ioutil.ReadFile(p)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return freetype.ParseFont(fontBytes)
|
|
}
|