Reputation: 23
I recently started using pillow for some project but I can't manage to generate a image with a list object. Every int in the list has a value between 0 and 255. So this is my relevant code:
img = Image.new('L',(width,height))
img.putdata(pixel)
img.save('img.png')
The output is always a completely black picture, even when I change every element in pixel to 0. I also tried using 'RGB' mode istead of 'L' mode, but then I get this error:
SystemError: new style getargs format but argument is not a tuple
I don't really undestand the error, I also changed the list, so that It holds all 3 RGB values as tuples.
Any idea what the problems might be?
Thanks in advance!
Upvotes: 1
Views: 2098
Reputation: 1049
Use like this:
from PIL import Image
pixel = []
for i in range(300*100):
pixel.append((255,0,0))
for i in range(300*100):
pixel.append((0,255,0))
for i in range(300*100):
pixel.append((0,0,255))
img = Image.new('RGB',(300,300))
img.putdata(pixel)
img.show()
Then you get:
SystemError: new style getargs format but argument is not a tuple
means you should use rgb like the "(R,G,B)" (a tuple).
Upvotes: 2