Skip to content

Instantly share code, notes, and snippets.

@mtvee
Created February 27, 2016 13:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save mtvee/d7a4bd450e3cd6766580 to your computer and use it in GitHub Desktop.
Save mtvee/d7a4bd450e3cd6766580 to your computer and use it in GitHub Desktop.
Convert plain text to XP format used by REXPaint
#
# 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