Python 生成随机验证码(数字与大小写字母组合,验证码图像旋转并添加图像噪声,生成bmp图像)
代码如下:
from array import array
import random
import cv2
import PIL.ImageFont as ImageFont
from PIL import Image
import numpy as np
import matplotlib.pyplot as plt
# http://mirrors.aliyun.com/pypi/simple/
class bmp:
""" bmp data structure """
def __init__(self, w=1080, h=1920, color = 0xffffff):
self.w = w
self.h = h
self.gen_bmp_header()
self.paint_bgcolor(color)
def calc_data_size (self):
if((self.w*3)%4 == 0):
self.dataSize = self.w * 3 * self.h
else:
self.dataSize = (((self.w * 3) // 4 + 1) * 4) * self.h
self.fileSize = self.dataSize + 54
def conv2byte(self, l, num, len):
tmp = num
for i in range(len):
l.append(tmp & 0x000000ff)
tmp >>= 8
def gen_bmp_header (self):
self.calc_data_size();
self.bmp_header = [0x
Python生成随机验证码图像

最低0.47元/天 解锁文章
1482

被折叠的 条评论
为什么被折叠?



