How to convert a RGBA image to a RGB image with PIL in Python

Converting a RGBA PNG image to a RGB JPG image returns a flattened image with a white background.

Solution for How to convert a RGBA image to a RGB image with PIL in Python : You can use PIL.Image.paste() to create a RGB version of the RGBA image Call PIL.Image.load() to load the pixel data. Then call PIL.Image.new(mode, size, color) with mode as “RGB”, size as the original image size, and color as (255, 255, 255) to create a new RGB image. Use PIL.Image.paste(image, box, mask) with image as the original image and mask as the original image’s alpha channel using PIL.Image.split(). PIL.Image.split() returns a tuple of individual image bands from an image of (red, green, blue, alpha). To get the alpha channel, index into 3. Then use PIL.Image.save(filename, format, quality) using the filename filename, the format override format, and the quality of the new image.


how-to-convert-a-rgba-image-to-a-rgb-image-with-pil-in-python