48 lines
1.5 KiB
Python
48 lines
1.5 KiB
Python
|
|
#!/usr/bin/env python3
|
||
|
|
import os
|
||
|
|
import subprocess
|
||
|
|
import glob
|
||
|
|
|
||
|
|
KRA_DIR = "_tmp/drop_shadow_kra_set"
|
||
|
|
PNG_DIR = "_tmp/drop_shadow_png_kra_set"
|
||
|
|
|
||
|
|
def main():
|
||
|
|
kra_files = glob.glob(os.path.join(KRA_DIR, "*.kra"))
|
||
|
|
if not kra_files:
|
||
|
|
print(f"No .kra files found in {KRA_DIR}. Run generate_kra_set.py first.")
|
||
|
|
return
|
||
|
|
|
||
|
|
os.makedirs(PNG_DIR, exist_ok=True)
|
||
|
|
print(f"Found {len(kra_files)} KRA files. Beginning headless export via Krita CLI...")
|
||
|
|
|
||
|
|
# Check if Krita exists
|
||
|
|
try:
|
||
|
|
subprocess.run(["krita", "--version"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||
|
|
except FileNotFoundError:
|
||
|
|
print("Error: 'krita' executable not found in your PATH.")
|
||
|
|
print("Please install Krita or run this script in an environment where Krita is available.")
|
||
|
|
return
|
||
|
|
|
||
|
|
count = 0
|
||
|
|
for kra_path in kra_files:
|
||
|
|
filename = os.path.basename(kra_path)
|
||
|
|
png_name = filename.replace(".kra", ".png")
|
||
|
|
png_path = os.path.join(PNG_DIR, png_name)
|
||
|
|
|
||
|
|
if os.path.exists(png_path):
|
||
|
|
continue
|
||
|
|
|
||
|
|
print(f"Exporting {filename} -> {png_name}...")
|
||
|
|
# Krita headless export command
|
||
|
|
cmd = ["krita", kra_path, "--export", "--export-filename", png_path]
|
||
|
|
res = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||
|
|
if res.returncode == 0:
|
||
|
|
count += 1
|
||
|
|
else:
|
||
|
|
print(f" FAILED to export {filename}: {res.stderr.decode()}")
|
||
|
|
|
||
|
|
print(f"Done. Successfully exported {count} files to {PNG_DIR}.")
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
main()
|