-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtypeToHandwritten.py
78 lines (74 loc) · 2.26 KB
/
typeToHandwritten.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# -*- coding: utf-8 -*-
"""
Created on Thu Apr 16 17:52:19 2020
@author: Arvind Krishna
@ github.com/ArvindAROO
"""
from PIL import Image
BG = Image.open("imagesFiles/bg.png")
#creating the instance of background image
sizeOfSheet = BG.width
gap, _ = 50, 25
#size of each image or character
#these are the only allowed characters
allowedChars = 'qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM,.?! 1234567890'
def writeIt(char):
"""Takes indivial chars and adds them to image"""
global gap, _
if char == '\n':
gap = 50
_ += 200
else:
#this will generate and open the image file
char.lower()
cases = Image.open("imagesFiles/%s.png"%char)
BG.paste(cases, (gap, _))
size = cases.width
gap += size
del cases
def caller(word):
global gap, _
if gap > sizeOfSheet - 100*(len(word)):
gap = 50
_ += 200
#print("word revieced by caller is {} and its size is {}".format(word, len(word)))
#this works on a word by word process
for letter in word:
if letter in allowedChars:
if letter.islower():
pass
elif letter.isupper():
letter = letter.lower()
letter += 'upper'
elif letter == '.':
letter = "fullstop"
elif letter == '!':
letter = 'exclamation'
elif letter == '?':
letter = 'question'
elif letter == ',':
letter = 'comma'
writeIt(letter)
#naming the character
#upper is appended to upper case characters
def dataHandling(Input):
"""Handles the input"""
wordlist=Input.split(' ')
for i in wordlist:
caller(i)
writeIt('space')
writeIt('\n')
if __name__ == '__main__':
try:
fileName = input("Enter file name: ")
with open(fileName, 'r') as File:
text = File.readlines()
for line in text:
dataHandling(line)
File.close()
if(".txt" in fileName):
BG.save(fileName[:-4]+'.bmp')
else:
BG.save(fileName+'.bmp')
except Exception as E:
print(E)