Created
September 28, 2022 10:17
-
-
Save larryhou/e2763d0cc2d69b438be3accbc4c6284f to your computer and use it in GitHub Desktop.
Concat cubemap slices into one big image with 4:3 aspect ratio
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
#!/usr/bin/env python | |
from email.mime import image | |
import os | |
import sys | |
from PIL import Image | |
def main(): | |
canvas = None # type: Image | |
data = [(2,1),(0,1),(1,0),(1,2),(1,1),(3,1)] | |
size = (0, 0) | |
dir = '.' | |
for n, name in enumerate(sys.argv[1:]): | |
print(n, name) | |
slice = Image.open(name) | |
if not canvas: | |
size = slice.size[0], slice.size[0] | |
dir = os.path.dirname(os.path.abspath(name)) | |
canvas = Image.new('RGB', size=(size[0]*4, size[1]*3)) | |
if size != slice.size: | |
slice = slice.resize(size=size, resample=Image.Resampling.BICUBIC) | |
slot = data[n] | |
canvas.paste(slice, (slot[0]*size[0],slot[1]*size[1])) | |
if n >= 6: break | |
if not canvas: raise Exception('invalid arguments: {}'.format(sys.argv[1:])) | |
filename = os.path.join(dir, 'cubemap.tga') | |
canvas.save(filename) | |
print('>> {}'.format(filename)) | |
if __name__ == '__main__': main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment