+

Apply changes to all images in this folder — Using Python PIL

Let`s install all the necessary modules —

 pip3 install pillow pip3 install os-sys 

We will analyze all images in the folder to apply changes / operations to all of them at the same time.

# Code for applying operations to all images
# there is one in the folder followed by another
# operations such as rotate, crop,

from PIL import Image

from PIL import ImageFilter

import os

 

 def main ():

# path to folder containing raw images

inPath = " E: Python.Engineering images "

  

# path to the folder where the modified image will be located

outPath = "E: Python.Engineering images_rotated "

  

  for imagePath in os.listdir (inPath):

# imagePath contains the name of the image

  inputPath = os.path.join ( (inPath, imagePath)

  

# inputPath contains the full directory name

  img = Image. open (inputPath)

 

fullOutPath = os.path.join ( (outPath, `invert_` + imagePath)

# fullOutPa th contains the path to the output

# image to generate

img.rotate ( 90 ). save (fullOutPath)

 

print (fullOutPath)

 
# Driver function

if __ name__ = = `__main__` :

  main ()

Sample images from folder —

Login:

image_sample1

Output:

invert_image_sample1


Get Solution for free from DataCamp guru