Skip to content

Instantly share code, notes, and snippets.

@cmartello
Created June 4, 2017 13:48
Show Gist options
  • Save cmartello/f4b508d092ccc8e059401e8c30fb7569 to your computer and use it in GitHub Desktop.
Save cmartello/f4b508d092ccc8e059401e8c30fb7569 to your computer and use it in GitHub Desktop.
Takes a directory of screenshots taken by NTR and stitches them together.
"""NTR for 3DS screenshots are dumped into two seperate files (top_ and bot_) and stored
in .bmp format. This script lets you merge those files into one (as a .png) fairly quickly.
Some caveats:
- This script is not clever and will not protect you from yourself. It pretty much expects
these files to be exactly 400x240 and 320x240 BMPs in RGB format. Anything else will
probably crash it.
- NTR has a habit of truncating screenshots randomly. As such, some files will be malformed
and the first point will apply.
Some good news though, this process takes a little over a minute for 140 odd screenshots, so
you won't be waiting long for your output. Also my one test run took my storage from 70 megs
to a little over 20, so that's a nice benefit.
"""
from PIL import Image
from glob import glob
from re import search
def merge_files(top, bot):
"""Merges the provided top_*.bmp and bot_*.bmp files created by
NTR's screenshot function into a single .png file. As the top screen
of the 3DS is slightly wider than the bottom, the bottom screen will
be centered and have black gutters to the left and right.
top = 400x240
bot = 320x240"""
# create a new output image
output = Image.new(mode='RGB', size=(400,480), color=(0,0,0))
# open the specified image files
t = Image.open(top)
b = Image.open(bot)
# paste the input into the output
output.paste(t, box=(0,0))
output.paste(b, box=(40,240))
# save her to disk
rex = search('(\d{4})', top)
if rex is not None:
fn = rex.group(1) + '.png'
output.save(fn, 'png')
# close our files
t.close()
b.close()
output.close()
if __name__ == '__main__':
files = glob('top_*.bmp')
for x in files:
print('merging %s and %s' % (x, 'bot' + x[3:]))
merge_files(x, 'bot' + x[3:])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment