2948 explained code solutions for 75 technologies

python-pillowHow to change pixel color

from PIL import Image

im = Image.open('/var/www/examples/small.png')
im.putpixel((10, 20), (255,255,255))

im.show()ctrl + c

import Pillow package modules


open given image with Pillow


sets color of a given pixel

(10, 20)

coordinates of the pixel to set color for


RGB color (in a tuple form) to set


displays resulting image

How to change pixel color, python pillow

Usage example

from PIL import Image

im = Image.open('/var/www/examples/heroine.png')
for i in range(0, 700):
  im.putpixel((i,i), (255,255,255))
  im.putpixel((i,i+1), (255,255,255))
  im.putpixel((i,i+2), (255,255,255))