Search code examples
python-3.ximagetype-conversionpython-imaging-libraryrgb

Convert RGBA to RGB in Python


What is the simplest and fastest way to convert an RGBA image in RGB using PIL? I just need to remove the A channel from some images.

I can't find a simple method to do this, I don't need to take background into consideration.


Solution

  • You probably want to use an image's convert method:

    import PIL.Image
    
    
    rgba_image = PIL.Image.open(path_to_image)
    rgb_image = rgba_image.convert('RGB')