shethjenil
commited on
Update HandWriteMachine.py
Browse files- HandWriteMachine.py +32 -31
HandWriteMachine.py
CHANGED
@@ -1,31 +1,32 @@
|
|
1 |
-
|
2 |
-
from
|
3 |
-
from tkinter.
|
4 |
-
from
|
5 |
-
import
|
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 |
-
img
|
31 |
-
img.
|
|
|
|
1 |
+
#https://github.com/Ankit404butfound/HomeworkMachine/tree/master/Image for image download
|
2 |
+
from PIL.Image import open as open_image , Image
|
3 |
+
from tkinter.simpledialog import askstring
|
4 |
+
from tkinter.filedialog import asksaveasfilename
|
5 |
+
from os import chdir
|
6 |
+
import sys
|
7 |
+
chdir(sys._MEIPASS)
|
8 |
+
def condition(cont: str) -> Image:
|
9 |
+
back = open_image("zback.png")
|
10 |
+
width,height = 50,0
|
11 |
+
for letter in cont:
|
12 |
+
if letter in "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+,.-? ":
|
13 |
+
if letter == " ":
|
14 |
+
letter = "zspace"
|
15 |
+
if letter.isupper():
|
16 |
+
letter = "c"+letter.lower()
|
17 |
+
if letter == ",":
|
18 |
+
letter = "coma"
|
19 |
+
if letter == ".":
|
20 |
+
letter = "fs"
|
21 |
+
if letter == "?":
|
22 |
+
letter = "que"
|
23 |
+
if width + 150 >= back.width:
|
24 |
+
height = height + 227
|
25 |
+
width = 50
|
26 |
+
cases = open_image(letter+".png")
|
27 |
+
back.paste(cases,(width,height))
|
28 |
+
width += cases.width
|
29 |
+
return back
|
30 |
+
img = condition(askstring("TEXT","Hand Written Text"))
|
31 |
+
img.show()
|
32 |
+
img.save(asksaveasfilename(filetypes=[("Image Files","*.png *jpg *jpeg *ico")],initialfile="Handwriting.png"))
|