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
PIL

import Pillow package modules

Image.new

create new PIL image object

mode='RGB'

create new image in RGB color mode

(300,300)

new image width and height

(150,200,50)

background color as an RGB tuple

.show()

displays resulting image