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

Python PIL | Image.new() method

Last Updated : 30 Jun, 2021
Improve
Suggest changes
Post a comment
Like Article
Like
Save
Share
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). 



Similar Reads

Convert OpenCV image to PIL image in Python
OpenCV is a huge open-source library for computer vision, machine learning, and image processing. OpenCV supports a wide variety of programming languages like Python, C++, Java, etc. It can process images and videos to identify objects, faces, or even the handwriting of a human. When it is integrated with various libraries, such as Numpy which is a
3 min read
How to merge a transparent PNG image with another image using PIL?
This article discusses how to put a transparent PNG image with another image. This is a very common operation on images. It has a lot of different applications. For example, adding a watermark or logo on an image. To do this, we are using the PIL module in Python. In which we use some inbuilt methods and combine the images in such a way that it loo
2 min read
Python PIL | Image.crop() method
PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities. PIL.Image.crop() method is used to crop a rectangular portion of any image. Syntax: PIL.Image.crop(box = None)Parameters: box - a 4-tuple defining the left, upper, right, and lower pixel coordinate.Return type: Image (Returns a rectangular regio
2 min read
Python PIL | Image.split() method
PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities. Image.split() method is used to split the image into individual bands. This method returns a tuple of individual image bands from an image. Splitting an “RGB” image creates three new images each containing a copy of one of the original bands (re
1 min read
Python PIL | Image.open() method
PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities. The Image module provides a class with the same name which is used to represent a PIL image. The module also provides a number of factory functions, including functions to load images from files, and to create new images. PIL.Image.open() Opens
2 min read
Python PIL | Image.point() method
PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities. The Image module provides a class with the same name which is used to represent a PIL image. The module also provides a number of factory functions, including functions to load images from files, and to create new images. Image.point() Maps this
2 min read
Python PIL | Image.show() method
PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities. The Image module provides a class with the same name which is used to represent a PIL image. The module also provides a number of factory functions, including functions to load images from files, and to create new images.Image.show() Displays th
1 min read
Python PIL | Image.save() method
PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities. The Image module provides a class with the same name which is used to represent a PIL image. The module also provides a number of factory functions, including functions to load images from files, and to create new images. Image.save() Saves this
2 min read
Python PIL | Image.quantize() method
PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities. The Image module provides a class with the same name which is used to represent a PIL image. The module also provides a number of factory functions, including functions to load images from files, and to create new images. Image.quantize() Conver
1 min read
Python PIL | Image.transpose() method
PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities. The Image module provides a class with the same name which is used to represent a PIL image. The module also provides a number of factory functions, including functions to load images from files, and to create new images.Image.transpose() Transp
2 min read
Article Tags :
Practice Tags :
three90RightbarBannerImg