Search code examples
pythonimagepython-imaging-library

python imaging library: Can I simply fill my image with one color?


How can I fill an existing image with a desired color?

(I am using from PIL import Image and from PIL import ImageDraw)

This command creates a new image filled with a desired color

image = Image.new("RGB", (self.width, self.height), (200, 200, 200))

But I would like to reuse the same image without the need of calling "new" every time.


Solution

  • Have you tried:

    image.paste(color, box)
    

    where box can be a 2-tuple giving the upper left corner, a 4-tuple defining the left, upper, right, and lower pixel coordinate, or None (same as (0, 0)).

    Since you want to fill the entire image, you can use the following:

    image.paste( (200,200,200), (0, 0, image.size[0], image.size[1]))