-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_pattern.py
More file actions
31 lines (22 loc) · 961 Bytes
/
generate_pattern.py
File metadata and controls
31 lines (22 loc) · 961 Bytes
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
import json
from PIL import Image
def create_reference_image(width, height):
ref_img = Image.new("RGBA", (width, height), (255, 255, 255, 255))
border_size = int(width * 0.05)
checker_size = 1
for y in range(height):
for x in range(width):
if x < border_size or x >= width - border_size or y < border_size or y >= height - border_size:
if (x // checker_size) % 2 == (y // checker_size) % 2:
ref_img.putpixel((x, y), (255, 0, 0, 255))
else:
ref_img.putpixel((x, y), (0, 255, 255, 255))
return ref_img
if __name__ == "__main__":
with open("config.json") as f:
config = json.load(f)
source_image_path = config["input"]["source"]
output_path = config["output"]["pattern"]
source_image = Image.open(source_image_path)
reference_image = create_reference_image(*source_image.size)
reference_image.save(output_path)