-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_i_t.py
36 lines (26 loc) · 1.38 KB
/
generate_i_t.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
import json
import os
from tqdm import tqdm
labels = json.load(open('./tmp/para_info.json'))
save_path = './tmp/i_t'
temp_save_path = './tmp/i_t_temp'
os.makedirs(save_path, exist_ok=True)
os.makedirs(temp_save_path, exist_ok=True)
text_image_size = '256x100'
image_size = '256x128'
gray_bg_path = './i_t_utils/gray_bg_256x128.png'
font_name = 'Noto Sans'
for crop_name, label in tqdm(labels.items()):
label = label['trans_txt']
save_file_path = os.path.join(save_path, f'{crop_name}.png')
temp_save_file_path = os.path.join(temp_save_path, f'{crop_name}.png')
input_text_command = f'convert -alpha set -background "rgb(121,127,141)" pango:\' \
<span font_stretch="semicondensed" foreground="#000000" font=" {font_name} 30 ">{label.lower()}</span> \
\' \png:-|convert - \\( +clone \\) +swap -background "rgb(121,127,141)" -layers merge +repage png:-|\
convert - -trim +repage -resize {text_image_size} {temp_save_file_path}'
os.system(input_text_command.encode('utf-8'))
finalInputTextCommand = 'composite -gravity Center ' + f'{temp_save_file_path}' + ' ' + gray_bg_path
finalInputTextCommand += ' png:-|'
finalInputTextCommand += 'convert - ' + save_file_path
os.system(finalInputTextCommand.encode('utf-8'))
os.system(f'rm -rf {temp_save_path}')