software / HandWriteMachine.py
shethjenil's picture
Update HandWriteMachine.py
980feb9 verified
#https://github.com/Ankit404butfound/HomeworkMachine/tree/master/Image for image download
from PIL.Image import open as open_image , Image
from tkinter.simpledialog import askstring
from tkinter.filedialog import asksaveasfilename
from os import chdir
import sys
chdir(sys._MEIPASS)
def condition(cont: str) -> Image:
back = open_image("zback.png")
width,height = 50,0
for letter in cont:
if letter in "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+,.-? \n":
if letter == " ":
letter = "zspace"
if letter.isupper():
letter = "c"+letter.lower()
if letter == ",":
letter = "coma"
if letter == ".":
letter = "fs"
if letter == "?":
letter = "que"
if width + 150 >= back.width:
height = height + 227
width = 50
if letter == "\n":
height += 227
width = 50
continue
cases = open_image(letter+".png")
back.paste(cases,(width,height))
width += cases.width
return back
img = condition(askstring("TEXT","Hand Written Text"))
img.show()
img.save(asksaveasfilename(filetypes=[("Image Files","*.png *jpg *jpeg *ico")],initialfile="Handwriting.png"))