def rgba2rgb(rgba, background=(1, 1, 1)):
 arr = _prepare_rgba_array(rgba)
 if (isinstance(background, tuple) and (len(background) != 3)):
  raise ValueError('the background must be a tuple with 3 items - the RGB color of the background. Got {0} items.'.format(len(background)))
 alpha = arr[..., (-1)]
 channels = arr[..., :(-1)]
 out = np.empty_like(channels)
 for ichan in range(channels.shape[(-1)]):
  out[..., ichan] = np.clip((((1 - alpha) * background[ichan]) + (alpha * channels[..., ichan])), a_min=0, a_max=1)
 return out

def rgba2rgb ( rgba , background = ( 1 , 1 , 1 ) ) : arr = _prepare_rgba_array ( rgba ) if ( isinstance ( background , tuple ) and ( len ( background ) != 3 ) ) : raise ValueError ( 'the background must be a tuple with 3 items - the RGB color of the background. Got {0} items.' . format ( len ( background ) ) ) alpha = arr [ ... , ( - 1 ) ] channels = arr [ ... , : ( - 1 ) ] out = np . empty_like ( channels ) for ichan in range ( channels . shape [ ( - 1 ) ] ) : out [ ... , ichan ] = np . clip ( ( ( ( 1 - alpha ) * background [ ichan ] ) + ( alpha * channels [ ... , ichan ] ) ) , a_min = 0 , a_max = 1 ) return out
rgba to rgb conversion .