bialix bialix - 3 months ago 49x
Python Question

How to invert colors of image with PIL (Python-Imaging)?

I need to convert series of images drawn as white on black background letters to images where white and black are inverted (as negative). How can I achieve this using PIL?


Try the following from the docs:

from PIL import Image
import PIL.ImageOps    

image ='your_image.png')

inverted_image = PIL.ImageOps.invert(image)'new_name.png')

Note: "The ImageOps module contains a number of 'ready-made' image processing operations. This module is somewhat experimental, and most operators only work on L and RGB images."