Skip to main content
Added example code
Source Link
Steve Barnes
  • 31.9k
  • 2
  • 29
  • 64

If you are happy with python and have PIL or Pillow installed then the answers to https://stackoverflow.com/questions/2498875/how-to-invert-colors-of-image-with-pil-python-imaging is a way to go.

You can add in a glob to find all of your images.

Something like:

from PIL import Image
from PIL import ImageOps
from glob import glob
import os
os.chdir('Documents/')  # Obviously this needs to be the top directory of your image tree
file_list = glob("**/*.jpg", recursive=True) # Get the filenames
outdir = "Converted"  # You can set this to what you like
for fname in file_list:  # For each filename
    image = Image.open(fname)  # Read it as an image
    image=image.convert('L')  # Make sure it is gray-scale
    image=ImageOps.invert(image)  # invert it
    newname = os.path.join(outdir, os.path.split(fname)[-1])  # Create a new name
    print("Saving Inverted", fname, "as", newname) 
    image.save(newname)  # Save it

If you are happy with python and have PIL or Pillow installed then the answers to https://stackoverflow.com/questions/2498875/how-to-invert-colors-of-image-with-pil-python-imaging is a way to go.

You can add in a glob to find all of your images.

If you are happy with python and have PIL or Pillow installed then the answers to https://stackoverflow.com/questions/2498875/how-to-invert-colors-of-image-with-pil-python-imaging is a way to go.

You can add in a glob to find all of your images.

Something like:

from PIL import Image
from PIL import ImageOps
from glob import glob
import os
os.chdir('Documents/')  # Obviously this needs to be the top directory of your image tree
file_list = glob("**/*.jpg", recursive=True) # Get the filenames
outdir = "Converted"  # You can set this to what you like
for fname in file_list:  # For each filename
    image = Image.open(fname)  # Read it as an image
    image=image.convert('L')  # Make sure it is gray-scale
    image=ImageOps.invert(image)  # invert it
    newname = os.path.join(outdir, os.path.split(fname)[-1])  # Create a new name
    print("Saving Inverted", fname, "as", newname) 
    image.save(newname)  # Save it
Source Link
Steve Barnes
  • 31.9k
  • 2
  • 29
  • 64

If you are happy with python and have PIL or Pillow installed then the answers to https://stackoverflow.com/questions/2498875/how-to-invert-colors-of-image-with-pil-python-imaging is a way to go.

You can add in a glob to find all of your images.