-
-
Save Arioksu/3aa411bb2fff0d2e8592a7431277c1a2 to your computer and use it in GitHub Desktop.
RPT to PNG
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
#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