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:

Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
Recommended Posts:
- Python PIL | GaussianBlur() method
- Python PIL | Kernel() method
- Python PIL | BoxBlur() method
- Python PIL | getbands() method
- Python PIL | logical_and() and logical_or() method
- Python PIL | ImageChops.subtract() method
- Python PIL | UnsahrpMask() method
- Python PIL | ImageChops.subtract() and ImageChops.subtract_modulo() method
- Python PIL | Image.crop() method
- Python PIL | ImageOps.expand() method
- Python PIL | ImageEnhance.Color() and ImageEnhance.Contrast() method
- Python PIL | ImageGrab.grabclipboard() method
- Python PIL | RankFilter() method
- Python PIL | ImageChops.screen() and ImageChops.offset() method
- Python PIL | MedianFilter() and ModeFilter() method
- Python PIL | Image.new() method
- Python PIL | getbands() and getextrema() method
- Python PIL | paste() and rotate() method
- Python PIL | ImageChops.darker() method
- Python PIL | Image.split() method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

