Skip to content

Instantly share code, notes, and snippets.

@wlkz
Last active July 25, 2023 12:43
Show Gist options
  • Save wlkz/d1b06f8afcc8fce07181ee80107ab194 to your computer and use it in GitHub Desktop.
Save wlkz/d1b06f8afcc8fce07181ee80107ab194 to your computer and use it in GitHub Desktop.
Krkr cg extractor
# Krkr cg extractor
# Author: wlkz
# Dependency: tlg2png (https://github.com/vn-tools/tlg2png), PIL
# License: WTFPL
import json
import os
import shutil
from pathlib import Path
from PIL import Image
evimage_path = Path('evimage')
tlg2png_path = Path('3rdparty') / 'tlg2png.exe'
output_path = Path('output')
output_path.mkdir(exist_ok=True)
source_paths = [path for path in evimage_path.iterdir() if path.is_dir()]
for source_path in source_paths:
base_name = source_path.stem
img_json_path = evimage_path / f'{base_name}.json'
if not img_json_path.exists():
continue
with img_json_path.open('r') as fp:
img_json = json.load(fp)
source_path = evimage_path / base_name
for tlg_path in source_path.glob('*.tlg'):
png_path = tlg_path.with_suffix('.png')
if png_path.exists():
continue
os.system(f'{tlg2png_path} {tlg_path} {png_path}')
base_layer = img_json['layers'][-1]
assert base_layer['top'] == base_layer['left'] == 0
cur_output_path = output_path / base_name
cur_output_path.mkdir(exist_ok=True)
base_path = None
for layer in img_json['layers'][::-1]:
assert layer['opacity'] == 255 and layer['type'] == 13 and layer['layer_type'] == 0
# layer['visible'] == 0 貌似是在不在界面显示?
if layer['visible'] == 0:
print('layer[\'visible\'] == 0')
output_target = cur_output_path / f'{base_name}_{layer["name"]}.png'
new_layer_path = source_path / f'{layer["layer_id"]}.png'
new_layer_img = Image.open(new_layer_path)
if new_layer_img.width != layer['width'] or new_layer_img.height != layer['height']:
# 意义不明的 0 * 0 图片,还是每组图的第 k 张,我也不知道哪出问题了
print(f'Bad layer: {output_target}')
continue
if layer["name"].endswith('a') or len(layer["name"]) == 1:
base_path = new_layer_path
if not output_target.exists():
if base_path == new_layer_path:
shutil.copy(base_path, output_target)
else:
base_img = Image.open(base_path)
base_img.paste(
new_layer_img, (layer['left'], layer['top']), new_layer_img)
base_img.save(output_target)
print(f'Output: {output_target}')
else:
print(f'Ignore: {output_target}')
continue
@wlkz
Copy link
Author

wlkz commented Apr 12, 2020

krkr_cg_extractor

用法

  1. 下载依赖
    Python 3.7+ 注意,安装过程中,务必勾上 Add Python 3.8 to PATH 选项。
    tlg2png
    KrkrExtract
  2. 解压游戏
    参见 KrkrExtract 的说明,解压游戏。
    务必勾选 Full Unpack
    evimage.xp3 解压即可。
  3. 解压游戏后在游戏目录会有 KrkrExtract_Output 的文件,在目录下新建 3rdparty 文件夹,将 tlg2png 全部文件放进去。
  4. 下载该代码,放到目录下。
  5. 在空白处 shift + 右键, 点上 “在此处打开 Powershell 窗口”, 运行
pip install pillow
python krkr_cg_extractor.py

enjoy~

后续维护在 https://github.com/wlkz/wlkz_scripts#krkr_cg_extractorpy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment