Advertisement
EXTREMEXPLOIT

ImageNoiser

Aug 1st, 2020
1,871
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.60 KB | None | 0 0
  1. from PIL import Image, ImageDraw, ImageFont
  2. import random, time
  3.  
  4. def GenerateImageRandomNumber(TextString, FileName, FontPath, TextSize):
  5.     try:
  6.         IMG_MODE = "RGB"
  7.         SIZE_X, SIZE_Y = 155, 135
  8.         IMG_SIZE = (SIZE_X, SIZE_Y)
  9.         r = lambda: random.randint(0,255)
  10.         IMG_COLOR = '#%02X%02X%02X' % (r(),r(),r())
  11.         IMG_NAME = str(FileName) + str(".jpg")
  12.         IMG_FONT = ImageFont.truetype(FontPath, TextSize)
  13.         IMG_TEXT = TextString
  14.         IMG = Image.new(IMG_MODE, IMG_SIZE, IMG_COLOR)
  15.         Draw = ImageDraw.Draw(IMG)
  16.         Size_X, Size_Y = Draw.textsize(IMG_TEXT, font=IMG_FONT)
  17.         POSITION = (random.randint(0, SIZE_X-50)), (random.randint(0, SIZE_Y-50))
  18.         fillColour = '#%02X%02X%02X' % (r(),r(),r())
  19.         Draw.text(POSITION, IMG_TEXT, font=IMG_FONT, fill=fillColour)
  20.         IMG.save(IMG_NAME)
  21.  
  22.         return IMG
  23.  
  24.     except Exception as Ex:
  25.         print(Ex)
  26.  
  27. MathSymbols = [',', '.', '/', '=', '-', '*', '+']
  28. MathNames = ['DecimalDot', 'DecimalDot', 'Division', 'Equal', 'Minus', 'Multiplication', 'Plus']
  29. for i in range(10000):
  30.     if random.randint(0,1) == 0:
  31.         N = random.randint(0,9)
  32.         ImageName = f'./Math Symbols/Train/{N}/{time.time()}'
  33.         GenerateImageRandomNumber(str(N), ImageName, 'C:/Windows/Fonts/consola.ttf', random.randint(10,50))
  34.     else:
  35.         S = random.randint(0, len(MathNames)-1)
  36.         ImageName = f'./Math Symbols/Train/{MathNames[S]}/{time.time()}'
  37.         GenerateImageRandomNumber(MathSymbols[S], ImageName, 'C:/Windows/Fonts/consola.ttf', random.randint(10,50))
  38.     print(f'{i+1}/100000')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement