0

I am running a code which takes an image an changes it to RGB format using im.convert("RGB"). However, when I run this, it prints in the terminal UserWarning: Palette images with Transparency expressed in bytes should be converted to RGBA images, which, although it doesn't stop the program, is annoying and pops up every time. Is there any way to remove this?

EpicEfeathers
  • 106
  • 2
  • 12

1 Answers1

2

Convert images to RGBA

for image in os.listdir(path/to/img/dir):
  im = Image.open(image)
  # If is png image
  if im.format is 'PNG':
    # and is not RGBA
    if im.mode is not 'RGBA':
      im.convert("RGBA").save(f"{image}2.png")

reference

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
thunder
  • 93
  • 6