pil python putpixel rgba code example

Example 1: how to save an image with the same name after editing in python pillow module

import os
from PIL import Image

PATH = "F:\\FYP DATASET\\images\\outliers Dataset\\Not Outliers\\"
Copy_to_path="F:\\FYP DATASET\\images\\outliers Dataset\\"

for filename in os.listdir(PATH):
    img = Image.open(os.path.join(PATH, filename)) # images are color images
    img = img.resize((224,224), Image.ANTIALIAS)
    img.save(Copy_to_path+filename+'.jpeg')

Example 2: convert rgb image to binary in pillow

from PIL import Image

col = Image.open("cat-tied-icon.png")
gray = col.convert('1')
bw.save("result_bw.png")