#!/bin/python3 import pygame as pg pg.init() size = width, height = 960,640 font0 = pg.font.SysFont('liberationmono',15) img = pg.image.load(input('image:')) def returnL(txt,img=img,pos=(0,0),font=font0,prnt=True,col=(0,0,0),aali=False,format=width): yup = [""] i,j,w,h=0,0,0,0 imw = img.get_rect().width-font.size(' ')[0] imh = img.get_rect().height-font.size(' ')[1] while True: ttt = [" ",mcoeff(font.render(" ",False,col,(255,255,255)),img,(w,h))] for k in txt: if mcoeff(font.render(k,False,col,(255,255,255)),img,(w,h))>ttt[1]: ttt = [k,mcoeff(font.render(k,False,col,(255,255,255)),img,(w,h))] yup[j]+=ttt[0] w+=font.size(ttt[0])[0] if w>imw: j+=1 w=0 h+=font.size(yup[j-1])[1] print(yup[j-1],' h:',h) if h >=imh: break yup+=[""] i+=1 stri = " " j = 1 b = font0.render('\u0001',False,(0,0,0),(255,255,255)) c = font0.render(' ',False,(0,0,0),(255,255,255)) bx= font0.size('\u0001')[0] by= font0.size('\u0001')[1] def mcoeff(s1,s2,off): cx = s1.get_rect().width cy = s1.get_rect().height r = 0 for x in range(cx): for y in range(cy): s1x = s1.get_at((x,y)) s2x = s2.get_at((x+off[0],y+off[1])) r1= (s1x[0]-s2x[0]+s1x[1]-s2x[1]+s1x[2]-s2x[2])/3 if abs(r1)<128: r+=1 return abs(r)/(cx*cy) for i in list(range(1,688))+list(range(7680,8191))+list(range(4608,5873))+list(range(8448,9115))+list(range(9280,10496)): try: t=eval('\'\\u'+('0000'+hex(i)[2:])[-4:]+'\'') t.encode('utf-8') a =font0.render(t,False,(0,0,0),(255,255,255)) if font0.size(t)[0] == font0.size("a"+t)[0] or font0.size(t) != font0.size(' ') or t in ['\n','\a','\b','\e','\f','\r','\t','\v']: continue for x in range(bx): for y in range(by): if a.get_at((x, y)) != b.get_at((x,y)) and a.get_at((x,y)) != c.get_at((x,y)) : j+=1 stri+=t break else: continue break except: pass returnL(stri)