Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from PIL import Image, ImageDraw, ImageFont
- import random, time
- def GenerateImageRandomNumber(TextString, FileName, FontPath, TextSize):
- try:
- IMG_MODE = "RGB"
- SIZE_X, SIZE_Y = 155, 135
- IMG_SIZE = (SIZE_X, SIZE_Y)
- r = lambda: random.randint(0,255)
- IMG_COLOR = '#%02X%02X%02X' % (r(),r(),r())
- IMG_NAME = str(FileName) + str(".jpg")
- IMG_FONT = ImageFont.truetype(FontPath, TextSize)
- IMG_TEXT = TextString
- IMG = Image.new(IMG_MODE, IMG_SIZE, IMG_COLOR)
- Draw = ImageDraw.Draw(IMG)
- Size_X, Size_Y = Draw.textsize(IMG_TEXT, font=IMG_FONT)
- POSITION = (random.randint(0, SIZE_X-50)), (random.randint(0, SIZE_Y-50))
- fillColour = '#%02X%02X%02X' % (r(),r(),r())
- Draw.text(POSITION, IMG_TEXT, font=IMG_FONT, fill=fillColour)
- IMG.save(IMG_NAME)
- return IMG
- except Exception as Ex:
- print(Ex)
- MathSymbols = [',', '.', '/', '=', '-', '*', '+']
- MathNames = ['DecimalDot', 'DecimalDot', 'Division', 'Equal', 'Minus', 'Multiplication', 'Plus']
- for i in range(10000):
- if random.randint(0,1) == 0:
- N = random.randint(0,9)
- ImageName = f'./Math Symbols/Train/{N}/{time.time()}'
- GenerateImageRandomNumber(str(N), ImageName, 'C:/Windows/Fonts/consola.ttf', random.randint(10,50))
- else:
- S = random.randint(0, len(MathNames)-1)
- ImageName = f'./Math Symbols/Train/{MathNames[S]}/{time.time()}'
- GenerateImageRandomNumber(MathSymbols[S], ImageName, 'C:/Windows/Fonts/consola.ttf', random.randint(10,50))
- print(f'{i+1}/100000')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement