0

Essentially I need to create an image 9 pixels wide x 7 high, black background, white smiley face on it. The white pixels are at (3,2), (3,5), (3,1), (5,1), (5,2), (5,5), (2,4), (6,4), (4,5) in a (w,h) format.

I assumed the background would default to black, but that hasn't happened, so I've added a line to make black the default. That also hasn't worked.

Whatever I have tried has just converted the entire image to one colour.

import PIL.Image as pim


width=8
height=6
my_image = pim.new("1", (width, height))    
for i in range(width):   
    for j in range(height):
        my_image.putpixel((i,j),(0))
        if i== 3 or 5 and j == 1 or 2 or 5:
            my_image.putpixel((i,j),(1))
        if i==2 or 6 and j ==4:
            my_image.putpixel((i,j),(1))
        if i==4 and j ==5:
            my_image.putpixel((i,j),(1)) 
HoopStart
  • 49
  • 4
  • 1
    Even if you correct this problem, directly setting pixels would be simpler and faster. Having pixel coordinates in a list and setting them as you iterate through this list even simpler. – Amadan Jul 20 '22 at 04:31
  • Oh my god that's so much easier, thank you! – HoopStart Jul 20 '22 at 05:01

0 Answers0