How to create blank image using Pillow, Python

Sometimes we need a blank image file to be created during execution of program, during processing required text or anything else can be added. Following is the sample program to create blank file using PIL, python.

You can decide file size and color as per your requirement.

################################################################################################
# name: 02_create_blank_image.py
# desc: Creates blank image files
# date: 2019-02-10
# Author: conquistadorjd
################################################################################################
from PIL import Image, ImageDraw
print('*** Program Started ***')
# image_font_path = 'imagepath_input = '/home/conquistador/code/github/python-01-utilities/image/fonts/'
# image_path_input = '/home/conquistador/code/github/python-01-utilities/image/input/'
image_path_output = '/home/conquistador/code/github/python-01-utilities/image/output/'
# image_name_input = '02_create_blank_image_01.jpg'
image_name_output = '02_create_blank_image_01.jpg'
mode = 'RGB' # for color image “L” (luminance) for greyscale images, “RGB” for true color images, and “CMYK” for pre-press images.
size = (640, 480)
color = (73, 109, 137)
im = Image.new(mode, size, color)
im.save(image_path_output + image_name_output )
im.show()
print('*** Program Ended ***')

Here is the output image

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.