Created
February 27, 2016 13:37
-
-
Save mtvee/d7a4bd450e3cd6766580 to your computer and use it in GitHub Desktop.
Convert plain text to XP format used by REXPaint
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
# | |
# translate a plain text file into the REXPaint file format | |
# | |
# NOTE: seems to come out rotated -90 for some reason | |
# writing order is off? idk | |
import struct | |
INFILE = 'plain_text.txt' | |
OUTFILE = 'fancy_text.xp' | |
def doit(): | |
fp = open(INFILE) | |
lines = fp.readlines() | |
fp.close() | |
with open(OUTFILE, 'wb') as fp: | |
fp.write(struct.pack('i', 1)) | |
fp.write(struct.pack('i', 1)) | |
fp.write(struct.pack('i', len(lines[0]))) | |
fp.write(struct.pack('i', len(lines))) | |
for line in lines: | |
for ch in line: | |
fp.write(struct.pack('i', ord(ch))) | |
fp.write(struct.pack('BBBBBB', 255,255,255,0,0,0)) | |
if __name__ == '__main__': | |
doit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment