import random
import string
from PIL import Image, ImageFont, ImageDraw
import numpy as np
import math
from scipy import misc
import os
characters = string.digits + string.ascii_letters
class GenerateImageCaptcha(object):
def __init__(self, width=160, height=60, fonts=None, font_sizes=None):
self._width = width
self._height = height
self._fonts = fonts or [r'C:\Windows\Fonts\arial.ttf']
self._font_sizes = font_sizes or (40, 45, 50)
self._truefonts = []
@property
def truefonts(self):
if self._truefonts:
return self._truefonts
self._truefonts = tuple([
ImageFont.truetype(n, s)
for n in self._fonts
for s in self._font_sizes
])
return self._truefonts
@staticmethod
def create_noise_curve(image, color):
curve_width = random.randint(0, 4)
if curve_width == 0:
return image
w, h = image.size
x1 = random.randint(0, int(w / 5))
y1 = random.randint(int(h / 5), h - int(h / 5))
for i