-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsync_overlay.py
53 lines (40 loc) · 1.54 KB
/
sync_overlay.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
51
52
53
from io import BytesIO
from PIL import Image
references = [
('template.png', (782, 1314))
]
canvas_width = 2000
canvas_height = 1500
canvas_scale = 3
unmasked_img = Image.new('RGBA', (canvas_width * canvas_scale, canvas_height * canvas_scale))
for reference in references:
file, coords = reference
x, y = coords
print(f'Preparing \'{file}\' at {coords}')
img = open(file, "rb").read()
img = Image.open(BytesIO(img))
img = img.resize((img.size[0] * canvas_scale, img.size[1] * canvas_scale), Image.Resampling.NEAREST)
pos = (x * canvas_scale, y * canvas_scale) # top left corner
unmasked_img.paste(img, pos)
print('Preparing mask')
mask_img = open("mask.png", "rb").read()
mask_i = Image.open(BytesIO(mask_img))
mask = Image.new("1", (canvas_width * canvas_scale, canvas_height * canvas_scale), 0)
mask.paste(mask_i)
print('Applying mask to image')
final_img = Image.new('RGBA', (canvas_width * canvas_scale, canvas_height * canvas_scale))
final_img = Image.composite(final_img, unmasked_img, mask)
# Compress the image by reducing the color palette from 32-bit color to 8-bit
print('Compressing image')
final_img = final_img.quantize()
print('Saving image')
final_img.save("overlay.png", optimize=True)
# Preparing raw overlay for the botnet
bot_img = Image.new('RGBA', (canvas_width, canvas_height))
for reference in references:
file, coords = reference
x, y = coords
img = open(file, "rb").read()
img = Image.open(BytesIO(img))
bot_img.paste(img, coords)
bot_img.save("overlay-bot.png", optimize=True)