Reputation: 1015
I have this code:
from PIL import Image, ImageColor
i = Image.new('1', (1, 1))
i.putpixel((0, 0), ImageColor.getcolor('black','1'))
i.save('simplePixel.png')
taken from this answer.
Running this produces a 1 pixel image that is black. If I change the color to red, for example:
ImageColor.getcolor('red','1')
I get a white pixel instead of red. I've tried yellow, green blue; they all result in a white pixel. How can I fix this?
Upvotes: 1
Views: 960
Reputation: 1015
I had the wrong mode:
from PIL import Image, ImageColor
i = Image.new('RGB', (1, 1))
i.putpixel((0, 0), ImageColor.getcolor('red','RGB'))
i.save('simplePixel.png')
I replaced the '1'
with 'RGB'
and now it works.
Upvotes: 2