The Wayback Machine - https://web.archive.org/web/20240217194910/https://www.geeksforgeeks.org/python-pil-image-new-method/
Open In App
Related Articles

Python PIL | Image.new() method

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities. 
PIL.Image.new() method creates a new image with the given mode and size. Size is given as a (width, height)-tuple, in pixels. The color is given as a single value for single-band images, and a tuple for multi-band images (with one value for each band). 
We can also use color names. If the color argument is omitted, the image is filled with zero (this usually corresponds to black). If the color is None, the image is not initialized. This can be useful if you’re going to paste or draw things in the image.
 

Syntax: 
PIL.Image.new(mode, size) 
PIL.Image.new(mode, size, color)
Parameters: 
mode: The mode to use for the new image. (It could be RGB, RGBA) 
size: A 2-tuple containing (width, height) in pixels. 
color: What color to use for the image. Default is black. If given, this should be a single integer or floating point value for single-band modes, and a tuple for multi-band modes.
Return Value: An Image object. 
 


Code #1: 
 

Python3

# Imports PIL module
import PIL
 
# creating a image object (new image object) with
# RGB mode and size 200x200
im = PIL.Image.new(mode="RGB", size=(200, 200))
 
# This method will show image in any image viewer
im.show()

                    

Output: 
 


  
Code #2: 
 

Python3

# imports Pil module
import PIL
 
# creating image object which is of specific color
im = PIL.Image.new(mode = "RGB", size = (200, 200),
                           color = (153, 153, 255))
 
# this will show image in any image viewer
im.show()

                    

Output: 
 


One can alter the value of color tuple to get different colors or we can simply use color name (for single band images). 


Don't miss your chance to ride the wave of the data revolution! Every industry is scaling new heights by tapping into the power of data. Sharpen your skills and become a part of the hottest trend in the 21st century.

Dive into the future of technology - explore the Complete Machine Learning and Data Science Program by GeeksforGeeks and stay ahead of the curve.


Last Updated : 30 Jun, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads
Complete Tutorials