#NEWLINE# def BuildMultilayer( src_filenames ) : #NEWLINE# #INDENT# assert ( ( 1 <= len ( src_filenames ) ) and ( len ( src_filenames ) <= 4 ) ) #NEWLINE# imgs = [ Image . open ( filename ) for filename in src_filenames ] #NEWLINE# expected_size = imgs [ 0 ] . size #NEWLINE# image_mode = 'RGBA' #NEWLINE# for img in imgs : #NEWLINE# #INDENT# assert ( img . size == expected_size ) #NEWLINE# assert ( img . mode == image_mode ) #NEWLINE# #UNINDENT# alpha_bands = [ ] #NEWLINE# for img in imgs : #NEWLINE# #INDENT# img . load ( ) #NEWLINE# ( R , G , B , A ) = img . split ( ) #NEWLINE# new_img = Image . merge ( 'L' , ( A , ) ) #NEWLINE# alpha_bands . append ( new_img ) #NEWLINE# #UNINDENT# empty_band = Image . new ( 'L' , expected_size , 255 ) #NEWLINE# for i in xrange ( ( len ( image_mode ) - len ( alpha_bands ) ) ) : #NEWLINE# #INDENT# alpha_bands . append ( empty_band ) #NEWLINE# #UNINDENT# return Image . merge ( image_mode , alpha_bands )