-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathText To Handwriting.py
43 lines (33 loc) · 1.25 KB
/
Text To Handwriting.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
40
41
42
43
#Importing Library
from PIL import Image
from sys import argv
# if you'd rather not use the command line, put the path to your file here
fileName = "dummy.txt" # path of your text file
# read file that user wants converted from command line. If file can't be read, assign
# the file to a file in the directory
try:
txt=open(argv[1], "r")
except IndexError:
print("No file entered. Using default file...")
txt=open(fileName, "r")
except FileNotFoundError:
print("Could not find file. Using default file...")
txt=open(fileName, "r")
BG=Image.open("myfont/bg.png") #path of page(background)photo (I have used blank page)
sheet_width=BG.width
gap, ht = 0, 0
# for each letter in the uploaded txt file, read the unicode value and replace it with
# the corresponding handwritten file in the "myfont" folder.
for i in txt.read().replace("\n",""):
cases = Image.open("myfont/{}.png".format(str(ord(i))))
BG.paste(cases, (gap, ht))
size = cases.width
height=cases.height
#print(size)
print("Running...........")
gap+=size
if sheet_width < gap or len(i)*115 >(sheet_width-gap):
gap,ht=0,ht+140
print(gap)
print(sheet_width)
BG.show()