-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpil-color-test.py
47 lines (34 loc) · 1.25 KB
/
pil-color-test.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
from inky.auto import auto
from PIL import Image,ImageDraw,ImageFont,ImageColor
# Define the size of the image
image_width = 800
image_height = 480
# Create a new image with a white background
image = Image.new("RGB", (image_width, image_height), "white")
draw = ImageDraw.Draw(image)
# Define the font and font size
font_size = 10
font = ImageFont.truetype("/usr/share/fonts/truetype/Urbanist-Thin.ttf", font_size)
# Get a list of all PIL colors
colors = list(ImageColor.colormap.keys())
# Calculate the number of columns and rows
num_columns = 10
num_rows = len(colors) // num_columns + 1
# Draw examples of each color with their names
for i, color in enumerate(colors):
column = i % num_columns
row = i // num_columns
# Calculate the position of the color example
x = column * (image_width // num_columns)
y = row * (image_height // num_rows)
# Draw a rectangle with the color
draw.rectangle([(x, y), (x + image_width // num_columns, y + image_height // num_rows)], fill=color)
# Draw the color name
draw.text((x, y), color, font=font, fill="black")
# Save the image
image.save("color_examples.png")
inky = auto(ask_user=True, verbose=True)
saturation = 1
inky.set_image(image, saturation=saturation)
image.show()
inky.show()