import random from PIL import Image import matplotlib.pyplot as plt # Define pixel sizes for different levels pixel_sizes = [128, 96, 64, 32, 24, 16, 12, 8, 4, 2] # Function to pixelate an image def pixelate(image, pixel_size): # Reduce the image size small = image.resize((image.size[0] // pixel_size, image.size[1] // pixel_size), Image.Resampling.NEAREST) # Scale back to original size return small.resize(image.size, Image.Resampling.NEAREST) # dictionary of photo name and url celeb_list = ["Tom Cruise", "Jake Gyllenhal", "Natalie Portman", "Aubrey Plaza", "Oscar Isaac", "Kate Winslet", "Ellen DeGeneres"] celeb_folder = { "Tom Cruise" : "./Celebs/TomCruise.jpeg", "Jake Gyllenhal" : "./Celebs/JakeGyllenhal.jpg", "Natalie Portman" : "./Celebs/NataliePortman.png", "Kajol" : "./Celebs/Kajol.png", "Oscar Isaac" : "./Celebs/OscarIsaac.jpg", "Nayanthara" : "./Celebs/Nayanthara.jpg", "Dhanush" : "./Celebs/Dhanush.jpg", } def Clear(prev_size, photo=celeb_list[1], folder=celeb_folder, next=False): if next: index = celeb_list.index(photo) + 1 photo = celeb_list[index] print(f"Processing {photo}") image_path = folder[photo] img = Image.open(BytesIO(image_path)) for curr_size in pixel_sizes: if curr_size