-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.py
43 lines (30 loc) · 1.06 KB
/
script.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
from PIL import Image, ImageDraw, ImageFont
import math
chars = "sleepySLEEPY"[::-1]
char_array = list(chars)
charLength = len(char_array)
interval = charLength/256
scaleFactor = 0.09
char_width = 10
char_height = 18
def getChar(inputInt):
return char_array[math.floor(inputInt*interval)]
text_file = open("Output.txt", "w")
img = Image.open("test.jpg")
img = img.convert('RGB')
fnt = ImageFont.truetype('C:\\Windows\\Fonts\\lucon.ttf', 15)
width, height = img.size
img = img.resize((int(scaleFactor*width), int(scaleFactor*height*(char_width/char_height))), Image.NEAREST)
width, height = img.size
pix = img.load()
outputImage = Image.new('RGB', (char_width * width, char_height * height), color = (0, 0, 0))
d = ImageDraw.Draw(outputImage)
for i in range(height):
for j in range(width):
r, g, b = pix[j, i]
h = int(r/3 + g/3 + b/3)
pix[j, i] = (h, h, h)
text_file.write(getChar(h))
d.text((j*char_width, i*char_height), getChar(h), font = fnt, fill = (r, g, b))
text_file.write('\n')
outputImage.save('output.png')