-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakepreviews.py
More file actions
executable file
·40 lines (38 loc) · 1.79 KB
/
makepreviews.py
File metadata and controls
executable file
·40 lines (38 loc) · 1.79 KB
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
#!/usr/bin/python
from os import listdir
from os.path import join, isfile
from PIL import Image, ImageDraw
import xml.etree.ElementTree as ET
for f in listdir("./rc/"):
if "png" in f and not "preview" in f and isfile(join("./rc", f.replace(".png", ".xml"))):
with Image.open(join("./rc", f)) as im:
dst = Image.new('RGBA', (154, 500))
dst.paste((255, 255, 255), [0, 0, dst.size[0], dst.size[1]])
l = 154 - im.width
t = 500 - im.height
dst.paste(im, (0, 0))
preview = Image.new('RGBA', (154 * 3, 500))
preview.paste(dst, (0, 0))
tree = ET.parse(join("./rc", f.replace(".png", ".xml")))
root = tree.getroot()
rc = root.find("rc")
bpos = 1
legend = Image.new('RGBA', (154, 500))
legend.paste((255, 255, 255), [0, 0, legend.size[0], legend.size[1]])
ldraw = ImageDraw.Draw(legend)
ldraw.text((20, 10), f.replace(".png", ""), fill="black")
try:
for button in rc.findall("button"):
pp = [int(x.strip()) for x in button.attrib.get("pos", "0").split(",")]
p_x, p_y = pp[0], pp[1]
draw = ImageDraw.Draw(dst)
draw.ellipse((p_x - 10, p_y - 10, p_x + 10, p_y + 10), fill=(255, 255, 255, 50), outline=(255, 255, 0))
draw.text((p_x - 5, p_y - 5), str(bpos), fill="red")
txt = "%s - %s" % (str(bpos), button.attrib.get("id"))
ldraw.text((10, 20 + (bpos * 9)), txt, fill="black")
bpos += 1
except:
pass
preview.paste(dst, (155, 0))
preview.paste(legend, (155 + 154, 0))
preview.save(join("./previews", f))