from PIL import Image, ImageOps
from glob import glob
import os
os.chdir('/your/image/folder')
files = glob('*.jpg')
for f in files:
image = Image.open(f)
if image.mode == 'RGBA':
r,g,b,a = image.split()
rgb_image = Image.merge('RGB', (r,g,b))
inverted_image = ImageOps.invert(rgb_image)
r2,g2,b2 = inverted_image.split()
final_transparent_image = Image.merge('RGBA', (r2,g2,b2,a))
final_transparent_image.save('rev_' + f)
else:
inverted_image = ImageOps.invert(image)
inverted_image.save('rev_' + f)