Created
May 12, 2017 03:22
-
-
Save JasonMillward/e291b7572fe6a588bbadd30ab247a308 to your computer and use it in GitHub Desktop.
Extract .png files from a compiled sprite sheet Raw
This file contains hidden or 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 binascii | |
import re | |
import os | |
for directory, subdirectories, files in os.walk('.'): | |
for file in files: | |
if not file.endswith('.bin'): | |
continue | |
filenumber = 0 | |
with open(os.path.join(directory, file)) as f: | |
hexaPattern = re.compile( | |
r'(89504E47.*?49454E44AE426082)', | |
re.IGNORECASE | |
) | |
for match in hexaPattern.findall(binascii.hexlify(f.read())): | |
with open('{}-{}.png'.format(file, filenumber), 'wb+') as f: | |
f.write(binascii.unhexlify(match)) | |
filenumber += 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment