import warnings warnings.filterwarnings('ignore') from PIL import Image import os, json os.makedirs('examples/how/features', exist_ok=True) results = [] for i in range(1, 10): path = f'examples/how/input_local_archive/{i}.jpeg' img = Image.open(path) img_rgb = img.convert('RGB') # Save thumbnail thumb = img_rgb.resize((360, 480)) thumb.save(f'examples/how/features/thumb_{i}.jpg', 'JPEG', quality=85) # Get color info small = img_rgb.resize((50, 50)) pixels = list(small.getdata()) r = sum(p[0] for p in pixels) // len(pixels) g = sum(p[1] for p in pixels) // len(pixels) b = sum(p[2] for p in pixels) // len(pixels) # Get quadrant colors (top/bottom/left/right) w, h = img_rgb.size top = img_rgb.crop((0, 0, w, h//3)).resize((10,10)) mid = img_rgb.crop((0, h//3, w, 2*h//3)).resize((10,10)) bot = img_rgb.crop((0, 2*h//3, w, h)).resize((10,10)) def avg_color(region): px = list(region.getdata()) return (sum(p[0] for p in px)//len(px), sum(p[1] for p in px)//len(px), sum(p[2] for p in px)//len(px)) results.append({ 'index': i, 'size': img.size, 'format': img.format, 'avg_rgb': (r, g, b), 'top_rgb': avg_color(top), 'mid_rgb': avg_color(mid), 'bot_rgb': avg_color(bot), }) print(f'{i}.jpeg: size={img.size}, avg=({r},{g},{b}), top={avg_color(top)}, mid={avg_color(mid)}, bot={avg_color(bot)}') print('\nDone! Thumbnails saved to examples/how/features/')