Last active
March 3, 2023 19:44
-
-
Save NeonCarbide/97bbf5d7ee105651c768b1171d249d83 to your computer and use it in GitHub Desktop.
A small script to convert 1x .png colour palettes from LoSpec to .txt formatted for REXPaint -- REQUIRES: Pillow library https://pillow.readthedocs.io/en/stable/installation.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
from PIL import Image | |
BLACK = (0,0,0) | |
cnt = 0 | |
par = argparse.ArgumentParser(description='A small script to convert 1x .png colour palettes from LoSpec to .txt formatted for REXPaint') | |
par.add_argument('src', nargs=1, metavar='path', type=str, help='The filepath of the desired .png palette') | |
par.add_argument('tit', nargs=1, metavar='title', type=str, help='The name of the resulting .txt') | |
args = par.parse_args() | |
img = Image.open(args.src[0], 'r') | |
img = img.convert('RGB') | |
wid, hei = img.size | |
val = list(img.getdata()) | |
tit = args.tit[0] + '.txt' | |
txt = open(tit, 'w') | |
for i in range(0, 12): | |
for j in range(0, 16): | |
r,g,b = val[cnt] if cnt < wid else BLACK | |
txt.write(f'{{{r},{g},{b}}}{chr(0x9)}') | |
cnt += 1 | |
txt.write('\n') | |
txt.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment