Friday, June 12, 2026
HomeLanguagesPython PIL | putpixel() method

Python PIL | putpixel() method

PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities. The PixelAccess class provides read and write access to PIL.Image data at a pixel level.
Accessing individual pixels is fairly slow. If you are looping over all of the pixels in an image, there is likely a faster way using other parts of the Pillow API.

putpixel() Modifies the pixel at x, y. The color is given as a single numerical value for single band images, and a tuple for multi-band images

Syntax: putpixel(self, xy, color)

Parameters:

xy :The pixel coordinate, given as (x, y)
value: – The pixel value.

Returns: An Image with pixel .

Image Used:




   
# Importing Image from PIL package 
from PIL import Image
      
# creating a image object
image = Image.open(r'C:\Users\System-Pc\Desktop\python.png') 
  
width, height = image.size
  
for x in range(height):
    image.putpixel( (x, x), (0, 0, 0, 255) )
  
image.show()


Output:

Another example:Here we change the color parameter.
Image Used




# Importing Image from PIL package 
from PIL import Image
      
# creating a image object
image = Image.open(r'C:\Users\System-Pc\Desktop\ybear.jpg') 
  
width, height = image.size
  
for x in range(height):
    image.putpixel( (x, x), (10, 10, 10, 255) )
  
image.show()


Output:

RELATED ARTICLES

1 COMMENT

Most Popular

Dominic
32515 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6897 POSTS0 COMMENTS
Nicole Veronica
12013 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12109 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6964 POSTS0 COMMENTS