-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblend_images.py
82 lines (64 loc) · 2.27 KB
/
blend_images.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
"""For each class/job, blend all action and trait images."""
import json
import os
import pathlib
from PIL import Image
from typing import List
THIS_FILE_DIR_PATH = pathlib.Path(__file__).parent.resolve()
PARENT_CLASSES = {
'PLD': 'GLA',
'WAR': 'MRD',
'BRD': 'ARC',
'MNK': 'PGL',
'DRG': 'LNC',
'ROG': 'NIN',
'WHM': 'CNJ',
'SCH': 'ARC',
'BLM': 'THM',
'SMN': 'ARC'
}
def blend_images(img_paths: List[str]) -> Image:
"""Blend multiple images into a single image, weighting each image equally.
Parameters
----------
img_paths : List[str]
List of filepaths to image files.
Returns
-------
blended_image : PIL.Image
Blended image.
"""
blended_image = None
for i, img_path in enumerate(img_paths):
img = Image.open(img_path)
if not blended_image:
blended_image = img
else:
blended_image = Image.blend(blended_image, img, 1 / (i + 1))
return blended_image
for cj_json_filename in os.listdir(THIS_FILE_DIR_PATH / 'class_job_info'):
cj_json_path = THIS_FILE_DIR_PATH / 'class_job_info' / cj_json_filename
with open(cj_json_path, 'r') as infile:
cj_info = json.load(infile)
cj_abbrev = cj_info['Abbreviation']
print('Blending images for', cj_abbrev)
parent_info = None
if cj_abbrev in PARENT_CLASSES:
parent_class = PARENT_CLASSES[cj_abbrev]
parent_json_path = THIS_FILE_DIR_PATH / 'class_job_info' / f'{parent_class}.json'
with open(parent_json_path, 'r') as infile:
parent_info = json.load(infile)
cj_img_paths = []
for action in cj_info['Actions']:
cj_img_paths.append(action['Icon Path'])
if parent_info: # i.e. has a parent class
for action in parent_info['Actions']:
cj_img_paths.append(action['Icon Path'])
# for trait in cj_info['Traits']:
# cj_img_paths.append(trait['Icon Path'])
# if parent_info: # i.e. has a parent class
# for trait in parent_info['Traits']:
# cj_img_paths.append(trait['Icon Path'])
blended_image = blend_images(cj_img_paths)
cj_bi_out_path = THIS_FILE_DIR_PATH / 'icons_blended_hd' / 'actions_only' / f'{cj_info["Abbreviation"]}.png'
blended_image.save(cj_bi_out_path)