Skip to content

Instantly share code, notes, and snippets.

@f0ff886f
Created August 26, 2017 19:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save f0ff886f/38b559a2d12518124d8b0ced3ee164f0 to your computer and use it in GitHub Desktop.
Save f0ff886f/38b559a2d12518124d8b0ced3ee164f0 to your computer and use it in GitHub Desktop.
Small script to provide texture sizes and popularity of each resolution type.
#!/usr/bin/env python3
from PIL import Image
import argparse
import re
import os
parser = argparse.ArgumentParser(description='Process image sizes from Unity Build Report.')
parser.add_argument('-f', '--filename', default=os.path.join(os.getenv('LOCALAPPDATA'), 'Unity\Editor\Editor.log'))
args = parser.parse_args()
filename = args.filename
imgregex = re.compile('^.*% (.*jpg$|.*png$|.*tif$)$')
imgs = []
total = 0
with open(filename) as f:
for line in f:
try:
imgname = imgregex.findall(line)[0]
imgpath = '../' + imgname
img = Image.open(imgpath)
imgs.append({'width': img.size[0], 'height': img.size[1], 'path': imgname})
total += 1
except:
continue
imgs = sorted(imgs, key=lambda k: k['width'], reverse=True)
resos = {}
outfile = os.path.join(os.getenv('LOCALAPPDATA'), 'BuildTextureOutput.log')
with open(outfile, 'w') as output:
for i in imgs:
output.write('{}x{} {}\n'.format(i['width'], i['height'], i['path']))
resos['{}x{}'.format(i['width'], i['height'])] = resos.get('{}x{}'.format(i['width'], i['height']), 0) + 1
for reso in sorted(resos, key=resos.get, reverse=True):
output.write('{:>9} {:5} ({:.0f}%)\n'.format(reso, resos[reso], resos[reso] / total * 100))
print('Done. Results in {}'.format(outfile))
os.startfile(outfile)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment