-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathASCIIImageWriter.py
50 lines (37 loc) · 1.15 KB
/
ASCIIImageWriter.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
44
45
46
47
48
49
50
# -*- coding: utf-8 -*-
import sys
import os
from PIL import Image
from PIL import ImageDraw
import image2ascii
def about():
print """
Author : Steven Aubertin
File : {0}
Description : Convert text file to ASCII image.
Dependency : PIL (http://www.pythonware.com/products/pil/)
""".format(sys.argv[0])
def printUsage():
print """whatavar""".format(sys.argv[0])
def main(argv):
rootoutput = '/Users/xor/Desktop/output/'
rootdir = '/Users/xor/Desktop/frames/'
for filename in os.listdir(rootdir):
img = Image.open(rootdir + filename)
data = image2ascii.image2ascii(img)
w, h = img.size
im = Image.new('RGBA', (w * 10, h * 10), (0, 0, 0, 0))
draw = ImageDraw.Draw(im)
y = 0
x = 0
for d in data:
if d == '\r':
x += 10
y = 0
draw.text((x, y), d, (255, 255, 255))
y += 10
w, h = img.size
im.resize((w, h), Image.BICUBIC).save(rootoutput + filename)
return 0
if __name__ == "__main__":
sys.exit(main(sys.argv[1:]))