Custom Texture Packer with PIL; Part 2


Tue Nov 08 2022 14:10:11 GMT+0000 (Coordinated Universal Time)

Saved by @MaVCArt #python

from PIL import Image
import numpy

class RGBAPacker(object):
    def process(self, output_file, inputs=None):
    	# -- we assume "inputs" is a dictionary of image files, with the keys corresponding to the channels they want packing in.
    	inputs = inputs or dict()
    	r ='mask1')).convert('L')
        g ='mask2')).convert('L')
        # -- our procedurally generated blue channel is the multiplied result of the first and second masks. 
        # -- This is a super simple operation, but you can make this as complex as you like.
        b = numpy.asarray(r) * numpy.asarray(g)
        b = Image.fromarray(b)
        output = Image.merge('RGB', r, g, b)