9951 explained code solutions for 126 technologies

python-pillowHow to set background color

Background is set as a color argument of Image.new method:

from PIL import Image, ImageFilter

im = Image.new(mode='RGB', size=(300,300), color=(150,200,50))

im.show()ctrl + c

import Pillow package modules


create new PIL image object


create new image in RGB color mode


new image width and height


background color as an RGB tuple


displays resulting image