-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathimage.py
39 lines (25 loc) · 911 Bytes
/
image.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from turtle import width
from PIL import Image, ImageDraw, ImageFont
import random
def get_initials(fullname):
xs = (fullname)
name_list = xs.split()
initials = ""
for name in name_list: # go through each name
initials += name[0].upper() # append the initial
return initials
def createImage(name):
width = 512
height = 512
message = get_initials(name)
message = message
font = ImageFont.truetype("arial.ttf", size=250)
img = Image.new('RGB', (width, height), color=(10, 10, 90))
imgDraw = ImageDraw.Draw(img)
textWidth, textHeight = imgDraw.textsize(message, font=font)
xText = (width - textWidth) / 2.2
yText = (height - textHeight) / 2.8
imgDraw.text((xText, yText), message, font=font, fill=(240, 240, 240))
n = random.randint(10,99999999)
img.save(f"static/images/users/result{n}.png", "PNG")
return f"result{n}.png"