#I edited the code without testing to optimize it and hid the api because I think I've harmed it enough
Explore tagged Tumblr posts
achamocha · 1 year ago
Text
Anyway
```
from PIL import Image from numpy import asarray from time import sleep import requests
all_colors = [] for i in range(1,9):     image = Image.open(rf'./sky/{i}.jpg')     data = asarray(image)
    for i in data:         all_colors.append('#%02x%02x%02x' % tuple(i[95])) # 95 is the middle of the image
color_names = [] unique_color_dict = dict() for color in all_colors:     if color in unique_color_dict:         color_names.append(unique_color_dict[color])     else:         response = foo # query the api         name = response.json()["name"]["value"]         color_names.append(name)         unique_color_dict[color] = name         sleep(1) # let the poor api rest
intro = "[Image description: A long image of the phrase 'Do you love the color of the sky?' in black font over a gradient background of " medio = ", ".join(color_names) final = ", followed by the phrase in black font reading 'Which one?'. End ID]" total = intro+medio+final print(total)```
8 notes · View notes