Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -6,11 +6,12 @@ import shutil
|
|
6 |
import random
|
7 |
|
8 |
def get_dominant_color(image):
|
9 |
-
"""Get the dominant color of an image or return None."""
|
10 |
try:
|
11 |
-
|
12 |
-
|
13 |
-
|
|
|
14 |
except:
|
15 |
return None
|
16 |
|
@@ -29,7 +30,7 @@ def resize_and_pad(image, target_size):
|
|
29 |
new_height = target_size[1]
|
30 |
new_width = int(new_height * aspect_ratio)
|
31 |
|
32 |
-
# Use
|
33 |
img = img.resize((new_width, new_height), Image.Resampling.LANCZOS)
|
34 |
|
35 |
# Determine padding color
|
|
|
6 |
import random
|
7 |
|
8 |
def get_dominant_color(image):
|
9 |
+
"""Get the dominant color of an image as a single RGB value or return None."""
|
10 |
try:
|
11 |
+
# Convert the image to a smaller size to simplify color calculation
|
12 |
+
small_image = image.resize((1, 1)) # Reduce to 1x1 pixel
|
13 |
+
dominant_color = small_image.getpixel((0, 0)) # Get the only pixel's color
|
14 |
+
return dominant_color
|
15 |
except:
|
16 |
return None
|
17 |
|
|
|
30 |
new_height = target_size[1]
|
31 |
new_width = int(new_height * aspect_ratio)
|
32 |
|
33 |
+
# Use high-quality resampling for resizing
|
34 |
img = img.resize((new_width, new_height), Image.Resampling.LANCZOS)
|
35 |
|
36 |
# Determine padding color
|