diff --git a/captcha.go b/captcha.go index e5096c5..ec8f46c 100644 --- a/captcha.go +++ b/captcha.go @@ -17,7 +17,10 @@ type Result struct { // CreateByText: generate a new captcha func CreateByText(option OptionText) (*Result, error) { opt := getOptionByText(option) - text := opt.randomText() + text := opt.text + if text == "" { + text = opt.randomText() + } data, err := opt.createCaptcha(text) if err != nil { diff --git a/captcha_test.go b/captcha_test.go index e949c61..ae00143 100644 --- a/captcha_test.go +++ b/captcha_test.go @@ -72,3 +72,13 @@ func TestCreateCaptcha(t *testing.T) { require.NotEmpty(t, capt) require.NoError(t, err) } + +func TestCreateCaptchaWithText(t *testing.T) { + opt := getOptionByText(OptionText{ + Text: "abcd", + }) + capt, err := opt.createCaptcha(opt.text) + + require.NotEmpty(t, capt) + require.NoError(t, err) +} diff --git a/option.go b/option.go index 8f4bb5a..55395af 100644 --- a/option.go +++ b/option.go @@ -48,6 +48,10 @@ type OptionText struct { // The characters that can be displayed in the captcha. // Default: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 CharactersPreset string + + // Generate With Text + // Note: Text is optional. If not provided, it will be generated randomly + Text string } type OptionMath struct { @@ -100,6 +104,7 @@ type OptionMath struct { type option struct { size uint8 + text string width uint16 height uint16 isColor bool @@ -165,6 +170,7 @@ func getOptionByText(opt OptionText) *option { ignoreCharacters: opt.IgnoreCharacters, charactersPreset: charPreset, fontPath: opt.FontPath, + text: opt.Text, } }