1

I'm trying to get the rgba values of the pixels of an image.

Google suggests I use code similar to this:

from PIL import Image
im = Image.open("C:/Stuff/image.png", "r")
px = list(im.getdata())

My problem is the data not always being in rgba format.

On some images it does return rgba

[(0, 0, 0, 255), (0, 0, 0, 255), (0, 0, 255, 255), [...]

while on others it returns rgb

[(0, 0, 0), (0, 0, 0), (0, 0, 255), [...]

and on some it returns whatever this is

[0, 0, 1, [...]

Is there a way to always get rgba returned?

martineau
  • 119,623
  • 25
  • 170
  • 301
dtpnftscdsatp
  • 273
  • 1
  • 11

0 Answers0