Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -17,12 +17,13 @@ app.mount("/static", StaticFiles(directory="static"), name="static")
|
|
17 |
# Function to add padding
|
18 |
def fill_rectangle_cropper(img, padding_type):
|
19 |
# Calculate the average color of the image
|
20 |
-
avg_color_per_row = np.average(img, axis=0)
|
21 |
avg_color = np.average(avg_color_per_row, axis=0)
|
22 |
|
23 |
if padding_type == "top_bottom":
|
24 |
-
if
|
25 |
-
|
|
|
26 |
newimg = Image.new(
|
27 |
'RGB',
|
28 |
(img.width, new_height),
|
@@ -32,11 +33,12 @@ def fill_rectangle_cropper(img, padding_type):
|
|
32 |
newimg.paste(img, (0, padding_top))
|
33 |
return newimg
|
34 |
else:
|
35 |
-
return img # No
|
36 |
|
37 |
elif padding_type == "left_right":
|
38 |
-
if
|
39 |
-
|
|
|
40 |
newimg = Image.new(
|
41 |
'RGB',
|
42 |
(new_width, img.height),
|
@@ -46,7 +48,7 @@ def fill_rectangle_cropper(img, padding_type):
|
|
46 |
newimg.paste(img, (padding_left, 0))
|
47 |
return newimg
|
48 |
else:
|
49 |
-
return img # No
|
50 |
|
51 |
# Function for cropping and filling the image
|
52 |
def fill_rectangle_cropper1(img):
|
|
|
17 |
# Function to add padding
|
18 |
def fill_rectangle_cropper(img, padding_type):
|
19 |
# Calculate the average color of the image
|
20 |
+
avg_color_per_row = np.average(np.array(img), axis=0)
|
21 |
avg_color = np.average(avg_color_per_row, axis=0)
|
22 |
|
23 |
if padding_type == "top_bottom":
|
24 |
+
# Check if padding is needed for top/bottom
|
25 |
+
if img.height < img.width:
|
26 |
+
new_height = img.width # Make the height equal to width
|
27 |
newimg = Image.new(
|
28 |
'RGB',
|
29 |
(img.width, new_height),
|
|
|
33 |
newimg.paste(img, (0, padding_top))
|
34 |
return newimg
|
35 |
else:
|
36 |
+
return img # No padding needed if height >= width
|
37 |
|
38 |
elif padding_type == "left_right":
|
39 |
+
# Check if padding is needed for left/right
|
40 |
+
if img.width < img.height:
|
41 |
+
new_width = img.height # Make the width equal to height
|
42 |
newimg = Image.new(
|
43 |
'RGB',
|
44 |
(new_width, img.height),
|
|
|
48 |
newimg.paste(img, (padding_left, 0))
|
49 |
return newimg
|
50 |
else:
|
51 |
+
return img # No padding needed if width >= height
|
52 |
|
53 |
# Function for cropping and filling the image
|
54 |
def fill_rectangle_cropper1(img):
|