Total Complexity | 2 |
Total Lines | 20 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | from io import BytesIO |
||
2 | |||
3 | import requests |
||
4 | from PIL import Image |
||
5 | |||
6 | |||
7 | # Get dominant color from image |
||
8 | def get_dominant_color(url) -> int: |
||
9 | response = requests.get(url) |
||
10 | pil_img = Image.open(BytesIO(response.content)) |
||
11 | img = pil_img.copy() |
||
12 | img.convert("RGB") |
||
13 | img.resize((1, 1), resample=0) |
||
14 | dominant_color = img.getpixel((0, 0)) |
||
15 | try: |
||
16 | return_color = int('%02x%02x%02x' % (dominant_color[0], dominant_color[1], dominant_color[2]), 16) |
||
17 | except TypeError: |
||
18 | return_color = 0 |
||
19 | return return_color |
||
20 |