Skip to content

Instantly share code, notes, and snippets.

@Arioksu
Created October 4, 2020 20:31
Show Gist options
  • Save Arioksu/3aa411bb2fff0d2e8592a7431277c1a2 to your computer and use it in GitHub Desktop.
Save Arioksu/3aa411bb2fff0d2e8592a7431277c1a2 to your computer and use it in GitHub Desktop.
RPT to PNG
#Revision of this script by foone: https://gist.github.com/foone/469e3c0912a405011bee1e146bf07a55
#I had some problem with his script so I did a revison for Python 3.8
import struct,glob,os,zlib
from PIL import Image
OUTDIR='out'
if not os.path.exists(OUTDIR):
os.mkdir(OUTDIR)
for name in glob.glob('*.rpt'):
outpath=os.path.join(OUTDIR,name+'.png')
if os.path.exists(outpath):
continue
print(name)
with open(name, 'rb') as f:
data=zlib.decompress(f.read())
with open(name,'rb') as f:
imagetype = data[0x19]
w,_,h = struct.unpack('>HHH',data[0x22:0x28])
print('Type: {:02x} w:{} h:{}'.format(imagetype,w,h))
if w==0 or h==0:
print('Bad image!')
continue
img = Image.frombytes('RGBA', (w,h), data[0x40:0x40+w*h*4])
img.save(outpath)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment