build.modules.utils   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 16
dl 0
loc 20
rs 10
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A get_dominant_color() 0 12 2
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