forked from CRImier/pyLCI
-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathsplash.py
More file actions
46 lines (43 loc) · 1.6 KB
/
splash.py
File metadata and controls
46 lines (43 loc) · 1.6 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
41
42
43
44
45
from PIL import ImageOps, Image, ImageColor
def replace_color(icon, fromc, toc):
import numpy as np
icon = icon.convert("RGBA")
# from https://stackoverflow.com/questions/3752476/python-pil-replace-a-single-rgba-color
if isinstance(fromc, str):
fromc = ImageColor.getrgb(fromc)
data = np.array(icon)
r, g, b, a = data.T
areas = (r == fromc[0]) & (g == fromc[1]) & (b == fromc[2])
if isinstance(toc, str):
toc = ImageColor.getrgb(toc)
data[..., :-1][areas.T] = toc
return Image.fromarray(data)
def splash(i, o, color="white"):
if color is None:
color = "white"
if (o.width, o.height) == (128, 64):
image = Image.open("resources/splash.png").convert('1')
image = ImageOps.invert(image)
elif o.width >= 128 and o.height >= 64:
image = Image.open("resources/splash_big.png").convert('1')
image = ImageOps.invert(image)
size = o.width, o.height
image.thumbnail(size, Image.LANCZOS)
left = top = right = bottom = 0
width, height = image.size
if o.width > width:
delta = o.width - width
left = delta // 2
right = delta - left
if o.height > height:
delta = o.height - height
top = delta // 2
bottom = delta - top
image = ImageOps.expand(image, border=(left, top, right, bottom), fill="black")
else:
o.display_data("Welcome to", "ZPUI")
return
if color != "white":
image = replace_color(image, "white", color)
image = image.convert(o.device_mode)
o.display_image(image)