import random import string from PIL import Image from claptcha import Claptcha def randomString(): rndLetters = (random.choice(string.ascii_uppercase) for _ in range(6)) return "".join(rndLetters) # Initialize Claptcha object with random text, FreeMono as font, of size # 100x30px, using bicubic resampling filter and adding a bit of white noise c = Claptcha(randomString, "FreeMonospaced-7ZXP.ttf", (100, 30), resample=Image.BICUBIC, noise=0.3) text, _ = c.write('captcha1.png') print(text) # 'PZTBXB', string printed into captcha1.png text, _ = c.write('captcha2.png') print(text) # 'NEDKEM', string printed into captcha2.png # Change images' size to 150x90 and estimated margin to 25x25 c.size = (150, 90) c.margin = (25, 25) text, _ = c.write('captcha3.png') print(text) # 'XCQYVS', captcha3.png has different dimentions than # captcha1.png and captcha2.png
from claptcha import Claptcha font = "/Library/Fonts/AppleGothic.ttf" path = "./images/" for j in range(0, 10): for i in range(0, 100): c = Claptcha(str(j), font) c.size = (100, 100) c.margin = (5, 5) text, image = c.image text, bytes = c.bytes fileName = str(j) + "_" if i < 10: fileName = fileName + "00" + str(i) else: fileName = fileName + "0" + str(i) fileName = fileName + ".bmp" print(fileName) c.write(path + fileName)