Skip to content

Instantly share code, notes, and snippets.

@James-E-A
Last active May 3, 2022 20:06
Show Gist options
  • Save James-E-A/c30fd7fff73ed3ec54c74b8301ef9cfc to your computer and use it in GitHub Desktop.
Save James-E-A/c30fd7fff73ed3ec54c74b8301ef9cfc to your computer and use it in GitHub Desktop.
Extract preview image from Barotrauma .sub files
#!/usr/bin/env python3
import gzip, base64, xml.etree.ElementTree as ElementTree
# USAGE:
# cd steamapps/common/Barotrauma
# python3 extract_preview.py LocalMods/Foo/Foo.sub preview.png
# TESTED WITH SUBS GENERATED BY:
# - v0.17.12.0
def extract_preview(sub):
"""Take a Barotrauma .sub file as input and return the binary blob of its preview image"""
with gzip.open(sub, 'r') as f:
tree = ElementTree.parse(f)
root = tree.getroot()
im_encoded = root.attrib['previewimage']
return base64.b64decode(im_encoded)
def main(i, o):
with open(i, 'rb') as f_in,\
open(o, 'wb') as f_out:
im = extract_preview(f_in)
f_out.write(im)
if __name__ == '__main__':
import sys
main(*sys.argv[1:])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment