On blank canvas I want to draw a square, pixel by pixel, using Pillow.
I have tried using img.putpixel((30,60), (155,155,55)) to draw one pixel but it doesn't do anything.
from PIL import Image
def newImg():
img = Image.new('RGB', (1280,768))
img.save('sqr.png')
return img
wallpaper = newImg()
wallpaper.show()
Running the code you say you have tried totally works, see below.
To draw the rectangle, repeat the img.putpixel((30,60), (155,155,55)) command with other coordinates.
from PIL import Image
def newImg():
img = Image.new('RGB', (100, 100))
img.putpixel((30,60), (155,155,55))
img.save('sqr.png')
return img
wallpaper = newImg()
wallpaper.show()
sqr.png

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With