Skip to content

Instantly share code, notes, and snippets.

@JasonMillward
Created May 12, 2017 03:22
Show Gist options
  • Save JasonMillward/e291b7572fe6a588bbadd30ab247a308 to your computer and use it in GitHub Desktop.
Save JasonMillward/e291b7572fe6a588bbadd30ab247a308 to your computer and use it in GitHub Desktop.
Extract .png files from a compiled sprite sheet Raw
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