├── myfont ├── 0.png ├── 1.png ├── 2.png ├── 3.png ├── 4.png ├── 5.png ├── 6.png ├── 7.png ├── 8.png ├── 9.png ├── a.png ├── b.png ├── c.png ├── ca.png ├── cb.png ├── cc.png ├── cd.png ├── ce.png ├── cf.png ├── cg.png ├── ch.png ├── ci.png ├── cj.png ├── ck.png ├── cl.png ├── cm.png ├── cn.png ├── co.png ├── cp.png ├── cq.png ├── cr.png ├── cs.png ├── ct.png ├── cu.png ├── cv.png ├── cw.png ├── cx.png ├── cy.png ├── cz.png ├── d.png ├── e.png ├── f.png ├── fs.png ├── g.png ├── h.png ├── i.png ├── j.png ├── k.png ├── l.png ├── m.png ├── n.png ├── o.png ├── p.png ├── q.png ├── r.png ├── s.png ├── t.png ├── u.png ├── v.png ├── w.png ├── x.png ├── y.png ├── z.png ├── ang1.png ├── ang2.png ├── colon.png ├── coma.png ├── cur1.png ├── cur2.png ├── div.png ├── dol1.png ├── dol2.png ├── equal.png ├── mul.png ├── par1.png ├── par2.png ├── plus.png ├── que.png ├── quo.png ├── roll1.png ├── roll2.png ├── roll3.png ├── sqr1.png ├── sqr2.png ├── star.png ├── sub.png ├── BEroll1.png ├── BEroll2.png ├── BEroll3.png └── backpage.png ├── textToWord.jpg ├── .gitignore ├── countwordlen.py ├── help.py ├── MyText.txt ├── README.md └── maincode.py /myfont/0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/0.png -------------------------------------------------------------------------------- /myfont/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/1.png -------------------------------------------------------------------------------- /myfont/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/2.png -------------------------------------------------------------------------------- /myfont/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/3.png -------------------------------------------------------------------------------- /myfont/4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/4.png -------------------------------------------------------------------------------- /myfont/5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/5.png -------------------------------------------------------------------------------- /myfont/6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/6.png -------------------------------------------------------------------------------- /myfont/7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/7.png -------------------------------------------------------------------------------- /myfont/8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/8.png -------------------------------------------------------------------------------- /myfont/9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/9.png -------------------------------------------------------------------------------- /myfont/a.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/a.png -------------------------------------------------------------------------------- /myfont/b.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/b.png -------------------------------------------------------------------------------- /myfont/c.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/c.png -------------------------------------------------------------------------------- /myfont/ca.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/ca.png -------------------------------------------------------------------------------- /myfont/cb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/cb.png -------------------------------------------------------------------------------- /myfont/cc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/cc.png -------------------------------------------------------------------------------- /myfont/cd.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/cd.png -------------------------------------------------------------------------------- /myfont/ce.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/ce.png -------------------------------------------------------------------------------- /myfont/cf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/cf.png -------------------------------------------------------------------------------- /myfont/cg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/cg.png -------------------------------------------------------------------------------- /myfont/ch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/ch.png -------------------------------------------------------------------------------- /myfont/ci.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/ci.png -------------------------------------------------------------------------------- /myfont/cj.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/cj.png -------------------------------------------------------------------------------- /myfont/ck.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/ck.png -------------------------------------------------------------------------------- /myfont/cl.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/cl.png -------------------------------------------------------------------------------- /myfont/cm.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/cm.png -------------------------------------------------------------------------------- /myfont/cn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/cn.png -------------------------------------------------------------------------------- /myfont/co.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/co.png -------------------------------------------------------------------------------- /myfont/cp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/cp.png -------------------------------------------------------------------------------- /myfont/cq.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/cq.png -------------------------------------------------------------------------------- /myfont/cr.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/cr.png -------------------------------------------------------------------------------- /myfont/cs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/cs.png -------------------------------------------------------------------------------- /myfont/ct.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/ct.png -------------------------------------------------------------------------------- /myfont/cu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/cu.png -------------------------------------------------------------------------------- /myfont/cv.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/cv.png -------------------------------------------------------------------------------- /myfont/cw.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/cw.png -------------------------------------------------------------------------------- /myfont/cx.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/cx.png -------------------------------------------------------------------------------- /myfont/cy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/cy.png -------------------------------------------------------------------------------- /myfont/cz.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/cz.png -------------------------------------------------------------------------------- /myfont/d.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/d.png -------------------------------------------------------------------------------- /myfont/e.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/e.png -------------------------------------------------------------------------------- /myfont/f.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/f.png -------------------------------------------------------------------------------- /myfont/fs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/fs.png -------------------------------------------------------------------------------- /myfont/g.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/g.png -------------------------------------------------------------------------------- /myfont/h.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/h.png -------------------------------------------------------------------------------- /myfont/i.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/i.png -------------------------------------------------------------------------------- /myfont/j.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/j.png -------------------------------------------------------------------------------- /myfont/k.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/k.png -------------------------------------------------------------------------------- /myfont/l.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/l.png -------------------------------------------------------------------------------- /myfont/m.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/m.png -------------------------------------------------------------------------------- /myfont/n.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/n.png -------------------------------------------------------------------------------- /myfont/o.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/o.png -------------------------------------------------------------------------------- /myfont/p.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/p.png -------------------------------------------------------------------------------- /myfont/q.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/q.png -------------------------------------------------------------------------------- /myfont/r.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/r.png -------------------------------------------------------------------------------- /myfont/s.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/s.png -------------------------------------------------------------------------------- /myfont/t.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/t.png -------------------------------------------------------------------------------- /myfont/u.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/u.png -------------------------------------------------------------------------------- /myfont/v.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/v.png -------------------------------------------------------------------------------- /myfont/w.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/w.png -------------------------------------------------------------------------------- /myfont/x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/x.png -------------------------------------------------------------------------------- /myfont/y.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/y.png -------------------------------------------------------------------------------- /myfont/z.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/z.png -------------------------------------------------------------------------------- /myfont/ang1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/ang1.png -------------------------------------------------------------------------------- /myfont/ang2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/ang2.png -------------------------------------------------------------------------------- /myfont/colon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/colon.png -------------------------------------------------------------------------------- /myfont/coma.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/coma.png -------------------------------------------------------------------------------- /myfont/cur1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/cur1.png -------------------------------------------------------------------------------- /myfont/cur2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/cur2.png -------------------------------------------------------------------------------- /myfont/div.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/div.png -------------------------------------------------------------------------------- /myfont/dol1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/dol1.png -------------------------------------------------------------------------------- /myfont/dol2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/dol2.png -------------------------------------------------------------------------------- /myfont/equal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/equal.png -------------------------------------------------------------------------------- /myfont/mul.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/mul.png -------------------------------------------------------------------------------- /myfont/par1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/par1.png -------------------------------------------------------------------------------- /myfont/par2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/par2.png -------------------------------------------------------------------------------- /myfont/plus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/plus.png -------------------------------------------------------------------------------- /myfont/que.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/que.png -------------------------------------------------------------------------------- /myfont/quo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/quo.png -------------------------------------------------------------------------------- /myfont/roll1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/roll1.png -------------------------------------------------------------------------------- /myfont/roll2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/roll2.png -------------------------------------------------------------------------------- /myfont/roll3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/roll3.png -------------------------------------------------------------------------------- /myfont/sqr1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/sqr1.png -------------------------------------------------------------------------------- /myfont/sqr2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/sqr2.png -------------------------------------------------------------------------------- /myfont/star.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/star.png -------------------------------------------------------------------------------- /myfont/sub.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/sub.png -------------------------------------------------------------------------------- /textToWord.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/textToWord.jpg -------------------------------------------------------------------------------- /myfont/BEroll1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/BEroll1.png -------------------------------------------------------------------------------- /myfont/BEroll2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/BEroll2.png -------------------------------------------------------------------------------- /myfont/BEroll3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/BEroll3.png -------------------------------------------------------------------------------- /myfont/backpage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D4rsh11/textToHandwritten/HEAD/myfont/backpage.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # ### PYTHON 2 | # compiled bytecode 3 | __pycache__/ 4 | 5 | # virtual environment 6 | venv/ 7 | .venv/ 8 | 9 | # temp files 10 | output/ -------------------------------------------------------------------------------- /countwordlen.py: -------------------------------------------------------------------------------- 1 | from PIL import Image 2 | import os 3 | imgwidth={} 4 | 5 | for img in os.listdir('./myfont/'): 6 | if img.endswith('.png'): 7 | char,ext=os.path.splitext(img) 8 | # print(char) 9 | pic=Image.open("./myfont/"+img) 10 | imgwidth[char]=pic.width; 11 | -------------------------------------------------------------------------------- /help.py: -------------------------------------------------------------------------------- 1 | from maincode import getname, arr 2 | import os 3 | 4 | missing = [] 5 | for ch in arr: 6 | name = getname(ch) 7 | if not os.path.exists(f"myfont/{name}.png"): 8 | missing.append(f"{name}.png") 9 | 10 | print("Missing character images:") 11 | for file in missing: 12 | print(file) 13 | -------------------------------------------------------------------------------- /MyText.txt: -------------------------------------------------------------------------------- 1 | ^^Welcome# 2 | This code is a clever and dynamic system for generating stylized# 3 | text images using custom character graphics. # 4 | It simulates typesetting by placing individual letter images on a# 5 | page, complete with support for special formatting, tables, and# 6 | pagination. What makes it especially awesome is its graceful error# 7 | handling—it skips missing assets without breaking the flow,# 8 | ensuring smooth, uninterrupted execution. The modular design and# 9 | random spacing add a human-like touch, making it ideal for creative# 10 | text rendering or anti-automation tasks like CAPTCHA generation.# 11 | 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # textToHandwritten 2 | 3 | ### Convert text into handwriting 4 | 5 |  6 | 7 | ## Install PILLOW Library first using either of following two: 8 | 9 | ```bash 10 | pip install Pillow 11 | ``` 12 | If you have Pythons installed and want to install this for Python3: 13 | ```bash 14 | python3 -m pip install Pillow 15 | ``` 16 | --- 17 | > Change the path format to backslash in maincode.py if you are using Linux (Currently works for Windows) 18 | ## Procedure to use 19 | 1. Put the content you want to be handwritten in MyText file. 20 | 21 | 2. Follow formating rule as given below to format Output.(check MyText file as well) 22 | 23 | a. Use `#` to switch to the new line 24 | 25 | b. Use `^^` to align the text to centre(Applies to the whole line) 26 | 27 | c. Use `->` for Tab(You can't use multiple spaces as this is whitespace collapsing) 28 | 29 | 3. Run the `maincode.py` 30 | 31 | 4. Output will be generated in `final` directory with name done1.png or done2.png...etc. 32 | 33 | ### I have added few alphabets only. You can add your alphabets using following method. 34 | 35 | * #### If you want to add more alphabets follow following procedure for each alphabet. 36 | 37 | a. Write alphabet on plain white paper(with black pen). 38 | 39 | b. Capture a photo with high quality camera. 40 | 41 | c. Crop the letter as close as possible from all sides. 42 | 43 | d. Remove white background using any background remover tool. [link](https://onlinepngtools.com/create-transparent-png) 44 | 45 | e. Resize the image and set its height to 160px maintaining the ratio. [link](https://play.google.com/store/apps/details?id=com.vinson.shrinker&hl=en_IN&gl=US) 46 | 47 | f. Suppose if the alphabet is capital 'A' save image as ca.png 48 | 49 | g. else save it as a.png 50 | 51 | h. If it is any special symbol follow convention from the `maincode.py` function `getname()` 52 | 53 | 54 | ### > Refer the `myfont` directory for more help 55 | -------------------------------------------------------------------------------- /maincode.py: -------------------------------------------------------------------------------- 1 | from PIL import Image 2 | from countwordlen import imgwidth 3 | # import pytesseract 4 | import random 5 | import string 6 | import os 7 | 8 | width, height = 715, 760 9 | arr = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+,.-?:/*<>}{()=[]$" ' 10 | imgsource = "myfont/" 11 | pageheight = 7624 12 | pagewidth = 5940 13 | start = 715 14 | end = 5930 15 | pageno = 0 16 | 17 | def getpage(): 18 | global back, pageno 19 | try: 20 | pageno += 1 21 | bg = Image.open("myfont/backpage.png", 'r') 22 | back = Image.new('RGBA', (5952, 8088), (0, 0, 0, 0)) 23 | back.paste(bg, (0, 0)) 24 | except: 25 | print("backpage not found") 26 | exit() 27 | 28 | def savepage(): 29 | path = "final\\done" 30 | i = 1 31 | while os.path.exists(path + str(i) + ".png"): 32 | i += 1 33 | back.save(path + str(i) + ".png", "PNG") 34 | print("Saved done" + str(i) + ".png .......n") 35 | 36 | def pasteimg(case, start, height): 37 | global back 38 | try: 39 | cases = Image.open(imgsource + "%s.png" % case) 40 | back.paste(cases, (start, height), mask=cases) 41 | start = start + cases.width + random.randint(5, 15) 42 | except FileNotFoundError: 43 | # Silently skip missing image 44 | pass 45 | except Exception as e: 46 | print(f"Unexpected error with case '{case}': {e}") 47 | return start 48 | 49 | def getname(letter): 50 | symbol_map = { 51 | ",": "coma", 52 | ".": "fs", 53 | "?": "que", 54 | "<": "ang1", 55 | ">": "ang2", 56 | "{": "cur1", 57 | "}": "cur2", 58 | ":": "colon", 59 | "/": "div", 60 | "-": "sub", 61 | "(": "par1", 62 | ")": "par2", 63 | "[": "sqr1", 64 | "]": "sqr2", 65 | "*": "star", 66 | "=": "equal", 67 | "+": "plus", 68 | "$": lambda: "dol" + str(random.randint(1, 2)), 69 | '"': "quo" 70 | } 71 | 72 | if letter.isupper(): 73 | return "c" + letter.lower() 74 | elif letter in symbol_map: 75 | mapped = symbol_map[letter] 76 | return mapped() if callable(mapped) else mapped 77 | return letter 78 | 79 | def getwordpix(word): 80 | wordwid = 0 81 | for char in word: 82 | if char in arr: 83 | img = getname(char) 84 | try: 85 | wordwid += imgwidth[img] 86 | except KeyError: 87 | continue 88 | except Exception as e: 89 | print(f"Unexpected error with character '{img}': {e}") 90 | return wordwid 91 | 92 | def getnewline(start, cur, end, height): 93 | global back 94 | height = height + 244 95 | if height > pageheight: 96 | getnewpage() 97 | return start, 760 98 | else: 99 | start = 720 + (random.randint(0, 100)) 100 | return start, height 101 | 102 | def getnewpage(): 103 | savepage() 104 | getpage() 105 | 106 | def formatting(word, leng, start, cur, ecfnd): 107 | global height 108 | if leng >= 2: 109 | if word[:2] == "^^": 110 | word = word[2:] 111 | cur += (2418 - int(getwordpix(word) / 2)) 112 | if word[:2] == "->": 113 | word = word[2:] 114 | cur += 400 115 | return word, cur 116 | 117 | def checktag(content, i, height, start, cur, end): 118 | if content[i] == "