ruby的生成隨機驗證碼

2021-08-30 07:43:26 字數 1074 閱讀 3725

網上找的使用ruby生成的隨機驗證碼

require 'rubygems'

require 'rmagick'

class validationimage

include magick

attr_reader :code, :image

jiggle = 15

wobble = 15

def initialize(len = 4)

chars = ('a'..'z').to_a + ('0'..'9').to_a

rand_chars =

1.upto(len) #生成驗證碼

background_type = "netscape:" #彩條 "granite:" #花崗岩 "xc:#edf7e7" #指定背景色 "null:" #純黑

background = magick::imagelist.new(background_type) #背景畫布

canvas = magick::imagelist.new #新建乙個畫布

canvas.new_image(32*len, 30, magick::texturefill.new(background)) #把背景加到畫布上

gc = magick::draw.new #新建乙個畫筆

gc.font_family = 'times'

gc.pointsize = 20

cur = 10

#在畫布上把驗證碼寫上去?

rand_chars.each

cur += 30

}@code = rand_chars.to_s

@image = canvas.to_blob

endend

v=validationimage.new

#生成filename= file.new('c:\1.jpg',"w+")

filename.binmode

puts v.code

filename.puts v.image

filename.puts v.code

驗證碼隨機生成

pip install captcha驗證碼隨機生成 python 版本 3.6 captcha 版本 0.3 from captcha.image import imagecaptcha import numpy as np import matplotlib.pyplot as plt from...

隨機生成驗證碼

coding utf 8 created on mon sep 16 01 21 02 2019 author administrator import random from captcha.image import imagecaptcha import numpy as np from pil...

隨機生成驗證碼

private static int r private static int g private static int b private static stringbuffer buffer public static final char chars public static random ...