sort imgs.py
from PIL import Image import os unique_images = {} # Specify the directory containing the PNG files directory = r'J:\New folder' for filename in os.listdir(directory): if filename.endswith('.png'): img = Image.open(os.path.join(directory, filename)) if str(img.tobytes()) in unique_images: os.remove(os.path.join(directory, filename)) print(f"Deleted {filename}") else: unique_images[str(img.tobytes())] = filename print(f"Kept {filename}")