feat: Generate relics name image
3
.gitignore
vendored
@ -256,3 +256,6 @@ adb_port.ini
|
||||
!popup.exe
|
||||
*.zip
|
||||
.vscode/*
|
||||
|
||||
#Typeface
|
||||
*.ttf
|
BIN
assets/cn/relics/name/Band_of_Sizzling_Thunder.png
Normal file
After Width: | Height: | Size: 4.7 KiB |
BIN
assets/cn/relics/name/Belobog_of_the_Architects.png
Normal file
After Width: | Height: | Size: 5.6 KiB |
BIN
assets/cn/relics/name/Broken_Keel.png
Normal file
After Width: | Height: | Size: 3.5 KiB |
BIN
assets/cn/relics/name/Celestial_Differentiator.png
Normal file
After Width: | Height: | Size: 2.9 KiB |
BIN
assets/cn/relics/name/Champion_of_Streetwise_Boxing.png
Normal file
After Width: | Height: | Size: 4.0 KiB |
BIN
assets/cn/relics/name/Duran_Dynasty_of_Running_Wolves.png
Normal file
After Width: | Height: | Size: 4.6 KiB |
BIN
assets/cn/relics/name/Eagle_of_Twilight_Line.png
Normal file
After Width: | Height: | Size: 4.7 KiB |
BIN
assets/cn/relics/name/Firesmith_of_Lava_Forging.png
Normal file
After Width: | Height: | Size: 4.8 KiB |
BIN
assets/cn/relics/name/Firmament_Frontline_Glamoth.png
Normal file
After Width: | Height: | Size: 5.0 KiB |
BIN
assets/cn/relics/name/Fleet_of_the_Ageless.png
Normal file
After Width: | Height: | Size: 3.7 KiB |
BIN
assets/cn/relics/name/Forge_of_the_Kalpagni_Lantern.png
Normal file
After Width: | Height: | Size: 4.6 KiB |
BIN
assets/cn/relics/name/Genius_of_Brilliant_Stars.png
Normal file
After Width: | Height: | Size: 4.5 KiB |
BIN
assets/cn/relics/name/Guard_of_Wuthering_Snow.png
Normal file
After Width: | Height: | Size: 4.2 KiB |
BIN
assets/cn/relics/name/Hunter_of_Glacial_Forest.png
Normal file
After Width: | Height: | Size: 4.5 KiB |
BIN
assets/cn/relics/name/Inert_Salsotto.png
Normal file
After Width: | Height: | Size: 4.7 KiB |
BIN
assets/cn/relics/name/Iron_Cavalry_Against_the_Scourge.png
Normal file
After Width: | Height: | Size: 5.2 KiB |
BIN
assets/cn/relics/name/Izumo_Gensei_and_Takama_Divine_Realm.png
Normal file
After Width: | Height: | Size: 4.4 KiB |
BIN
assets/cn/relics/name/Knight_of_Purity_Palace.png
Normal file
After Width: | Height: | Size: 5.1 KiB |
BIN
assets/cn/relics/name/Longevous_Disciple.png
Normal file
After Width: | Height: | Size: 4.1 KiB |
BIN
assets/cn/relics/name/Messenger_Traversing_Hackerspace.png
Normal file
After Width: | Height: | Size: 5.1 KiB |
BIN
assets/cn/relics/name/Musketeer_of_Wild_Wheat.png
Normal file
After Width: | Height: | Size: 5.4 KiB |
BIN
assets/cn/relics/name/Pan_Cosmic_Commercial_Enterprise.png
Normal file
After Width: | Height: | Size: 4.5 KiB |
BIN
assets/cn/relics/name/Passerby_of_Wandering_Cloud.png
Normal file
After Width: | Height: | Size: 4.3 KiB |
BIN
assets/cn/relics/name/Penacony_Land_of_the_Dreams.png
Normal file
After Width: | Height: | Size: 5.3 KiB |
BIN
assets/cn/relics/name/Pioneer_Diver_of_Dead_Waters.png
Normal file
After Width: | Height: | Size: 5.0 KiB |
BIN
assets/cn/relics/name/Prisoner_in_Deep_Confinement.png
Normal file
After Width: | Height: | Size: 4.9 KiB |
BIN
assets/cn/relics/name/Rutilant_Arena.png
Normal file
After Width: | Height: | Size: 3.3 KiB |
BIN
assets/cn/relics/name/Sigonia_the_Unclaimed_Desolation.png
Normal file
After Width: | Height: | Size: 4.5 KiB |
BIN
assets/cn/relics/name/Space_Sealing_Station.png
Normal file
After Width: | Height: | Size: 3.0 KiB |
BIN
assets/cn/relics/name/Sprightly_Vonwacq.png
Normal file
After Width: | Height: | Size: 3.7 KiB |
BIN
assets/cn/relics/name/Talia_Kingdom_of_Banditry.png
Normal file
After Width: | Height: | Size: 5.0 KiB |
BIN
assets/cn/relics/name/The_Ashblazing_Grand_Duke.png
Normal file
After Width: | Height: | Size: 4.8 KiB |
BIN
assets/cn/relics/name/The_Wind_Soaring_Valorous.png
Normal file
After Width: | Height: | Size: 4.3 KiB |
BIN
assets/cn/relics/name/Thief_of_Shooting_Meteor.png
Normal file
After Width: | Height: | Size: 4.8 KiB |
BIN
assets/cn/relics/name/Wastelander_of_Banditry_Desert.png
Normal file
After Width: | Height: | Size: 5.0 KiB |
After Width: | Height: | Size: 5.4 KiB |
BIN
assets/en/relics/name/Band_of_Sizzling_Thunder.png
Normal file
After Width: | Height: | Size: 6.4 KiB |
BIN
assets/en/relics/name/Belobog_of_the_Architects.png
Normal file
After Width: | Height: | Size: 6.6 KiB |
BIN
assets/en/relics/name/Broken_Keel.png
Normal file
After Width: | Height: | Size: 3.0 KiB |
BIN
assets/en/relics/name/Celestial_Differentiator.png
Normal file
After Width: | Height: | Size: 6.0 KiB |
BIN
assets/en/relics/name/Champion_of_Streetwise_Boxing.png
Normal file
After Width: | Height: | Size: 8.5 KiB |
BIN
assets/en/relics/name/Duran_Dynasty_of_Running_Wolves.png
Normal file
After Width: | Height: | Size: 9.1 KiB |
BIN
assets/en/relics/name/Eagle_of_Twilight_Line.png
Normal file
After Width: | Height: | Size: 5.4 KiB |
BIN
assets/en/relics/name/Firesmith_of_Lava_Forging.png
Normal file
After Width: | Height: | Size: 6.4 KiB |
BIN
assets/en/relics/name/Firmament_Frontline_Glamoth.png
Normal file
After Width: | Height: | Size: 7.1 KiB |
BIN
assets/en/relics/name/Fleet_of_the_Ageless.png
Normal file
After Width: | Height: | Size: 5.0 KiB |
BIN
assets/en/relics/name/Forge_of_the_Kalpagni_Lantern.png
Normal file
After Width: | Height: | Size: 7.6 KiB |
BIN
assets/en/relics/name/Genius_of_Brilliant_Stars.png
Normal file
After Width: | Height: | Size: 6.0 KiB |
BIN
assets/en/relics/name/Guard_of_Wuthering_Snow.png
Normal file
After Width: | Height: | Size: 7.1 KiB |
BIN
assets/en/relics/name/Hunter_of_Glacial_Forest.png
Normal file
After Width: | Height: | Size: 5.7 KiB |
BIN
assets/en/relics/name/Inert_Salsotto.png
Normal file
After Width: | Height: | Size: 3.4 KiB |
BIN
assets/en/relics/name/Iron_Cavalry_Against_the_Scourge.png
Normal file
After Width: | Height: | Size: 8.7 KiB |
BIN
assets/en/relics/name/Izumo_Gensei_and_Takama_Divine_Realm.png
Normal file
After Width: | Height: | Size: 10 KiB |
BIN
assets/en/relics/name/Knight_of_Purity_Palace.png
Normal file
After Width: | Height: | Size: 6.0 KiB |
BIN
assets/en/relics/name/Longevous_Disciple.png
Normal file
After Width: | Height: | Size: 5.1 KiB |
BIN
assets/en/relics/name/Messenger_Traversing_Hackerspace.png
Normal file
After Width: | Height: | Size: 9.4 KiB |
BIN
assets/en/relics/name/Musketeer_of_Wild_Wheat.png
Normal file
After Width: | Height: | Size: 6.5 KiB |
BIN
assets/en/relics/name/Pan_Cosmic_Commercial_Enterprise.png
Normal file
After Width: | Height: | Size: 9.0 KiB |
BIN
assets/en/relics/name/Passerby_of_Wandering_Cloud.png
Normal file
After Width: | Height: | Size: 8.1 KiB |
BIN
assets/en/relics/name/Penacony_Land_of_the_Dreams.png
Normal file
After Width: | Height: | Size: 7.5 KiB |
BIN
assets/en/relics/name/Pioneer_Diver_of_Dead_Waters.png
Normal file
After Width: | Height: | Size: 7.1 KiB |
BIN
assets/en/relics/name/Prisoner_in_Deep_Confinement.png
Normal file
After Width: | Height: | Size: 7.5 KiB |
BIN
assets/en/relics/name/Rutilant_Arena.png
Normal file
After Width: | Height: | Size: 3.5 KiB |
BIN
assets/en/relics/name/Sigonia_the_Unclaimed_Desolation.png
Normal file
After Width: | Height: | Size: 9.2 KiB |
BIN
assets/en/relics/name/Space_Sealing_Station.png
Normal file
After Width: | Height: | Size: 6.0 KiB |
BIN
assets/en/relics/name/Sprightly_Vonwacq.png
Normal file
After Width: | Height: | Size: 5.4 KiB |
BIN
assets/en/relics/name/Talia_Kingdom_of_Banditry.png
Normal file
After Width: | Height: | Size: 7.1 KiB |
BIN
assets/en/relics/name/The_Ashblazing_Grand_Duke.png
Normal file
After Width: | Height: | Size: 7.4 KiB |
BIN
assets/en/relics/name/The_Wind_Soaring_Valorous.png
Normal file
After Width: | Height: | Size: 7.4 KiB |
BIN
assets/en/relics/name/Thief_of_Shooting_Meteor.png
Normal file
After Width: | Height: | Size: 6.7 KiB |
BIN
assets/en/relics/name/Wastelander_of_Banditry_Desert.png
Normal file
After Width: | Height: | Size: 8.5 KiB |
After Width: | Height: | Size: 12 KiB |
97
dev_tools/text_draw.py
Normal file
@ -0,0 +1,97 @@
|
||||
import cv2
|
||||
import re
|
||||
import numpy as np
|
||||
import os
|
||||
from PIL import ImageFont, ImageDraw, Image
|
||||
from module.config.utils import read_file
|
||||
from module.logger import logger
|
||||
|
||||
|
||||
def crop_to_text_edge(original_image):
|
||||
gray = cv2.cvtColor(original_image, cv2.COLOR_BGR2GRAY)
|
||||
|
||||
_, binary = cv2.threshold(gray, 100, 255, cv2.THRESH_BINARY_INV)
|
||||
|
||||
contours, _ = cv2.findContours(binary, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
|
||||
|
||||
x_min, y_min = float('inf'), float('inf')
|
||||
x_max, y_max = float('-inf'), float('-inf')
|
||||
|
||||
for contour in contours:
|
||||
x, y, w, h = cv2.boundingRect(contour)
|
||||
x_min = min(x_min, x)
|
||||
y_min = min(y_min, y)
|
||||
x_max = max(x_max, x + w)
|
||||
y_max = max(y_max, y + h)
|
||||
|
||||
cropped_image = original_image[y_min:y_max, x_min:x_max]
|
||||
return cropped_image
|
||||
|
||||
|
||||
def split_string_at_last_space(input_string):
|
||||
if all(ord(char) < 128 for char in input_string) and len(input_string) > 35:
|
||||
last_space_index = input_string.rfind(' ')
|
||||
|
||||
if last_space_index == -1:
|
||||
return input_string, ""
|
||||
|
||||
part1 = input_string[:last_space_index]
|
||||
part2 = input_string[last_space_index + 1:]
|
||||
|
||||
return part1, part2
|
||||
else:
|
||||
return input_string, ""
|
||||
|
||||
|
||||
def text_image_generator(chars, names, font, output_path='./'):
|
||||
for char, name in zip(chars, names):
|
||||
image_path = os.path.join(output_path, name + '.png')
|
||||
if (os.path.isfile(image_path)):
|
||||
logger.info(f'{name} already exists, skipping')
|
||||
continue
|
||||
else:
|
||||
part = ['', '']
|
||||
part = split_string_at_last_space(char)
|
||||
|
||||
image = np.ones((50, 370, 3), dtype=np.uint8) * 255
|
||||
|
||||
image_pil = Image.fromarray(cv2.cvtColor(image, cv2.COLOR_BGR2RGB))
|
||||
|
||||
draw = ImageDraw.Draw(image_pil)
|
||||
|
||||
draw.text((2, 0.5), part[0], font=font, fill=(0, 0, 0))
|
||||
draw.text((2, 25), part[1], font=font, fill=(0, 0, 0))
|
||||
|
||||
image = cv2.cvtColor(np.array(image_pil), cv2.COLOR_RGB2BGR)
|
||||
|
||||
crop_image = crop_to_text_edge(image)
|
||||
cv2.imencode('.png', crop_image)[1].tofile(image_path)
|
||||
logger.info(f'{name} generated')
|
||||
|
||||
|
||||
def relics_name_image_generator():
|
||||
font_en = ImageFont.truetype("./dev_tools/zh-cn.ttf", 20)
|
||||
font_cn = ImageFont.truetype("./dev_tools/zh-cn.ttf", 20)
|
||||
output_path_cn = './assets/cn/relics/name/'
|
||||
output_path_en = './assets/en/relics/name/'
|
||||
|
||||
with open('./tasks/relics/keywords/relics.py', 'r', encoding='utf-8') as file:
|
||||
content = file.read()
|
||||
|
||||
cn_pattern = re.compile(r"cn='([^']*)'")
|
||||
en_pattern = re.compile(r"en='([^']*)'")
|
||||
name_pattern = re.compile(r"name='([^']*)'")
|
||||
|
||||
cn_values = cn_pattern.findall(content)
|
||||
en_values = en_pattern.findall(content)
|
||||
name_values = name_pattern.findall(content)
|
||||
|
||||
text_image_generator(cn_values, name_values, font=font_cn, output_path=output_path_cn)
|
||||
text_image_generator(en_values, name_values, font=font_en, output_path=output_path_en)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
relics_name_image_generator()
|
||||
|
||||
|
||||
|