Spaces:
Sleeping
Sleeping
Commit
·
ce3eb76
1
Parent(s):
5eb76a8
Update app.py
Browse files
app.py
CHANGED
@@ -10,7 +10,7 @@ def hex_to_rgb(hex_code):
|
|
10 |
# Convert the hex code to RGB
|
11 |
return tuple(int(hex_code[i:i+2], 16) for i in (0, 2, 4))
|
12 |
|
13 |
-
def resize_and_overlay_image(input_image, reduction_percentage, shift_pixels, shift_pixels_ud, background_color,
|
14 |
# Check if the input image is empty
|
15 |
if input_image.size == 0:
|
16 |
return None
|
@@ -24,6 +24,10 @@ def resize_and_overlay_image(input_image, reduction_percentage, shift_pixels, sh
|
|
24 |
# Get the image dimensions
|
25 |
height, width = img.shape[:2]
|
26 |
|
|
|
|
|
|
|
|
|
27 |
# Crop the top and/or bottom of the image
|
28 |
img = img[crop_top:height - crop_bottom, :]
|
29 |
|
@@ -59,13 +63,13 @@ iface = gr.Interface(
|
|
59 |
gr.inputs.Slider(minimum=-150, maximum=150, step=10, default=0, label="Shift Pixels Left / Right"),
|
60 |
gr.inputs.Slider(minimum=-150, maximum=250, step=10, default=0, label="Shift Pixels Up / Down"),
|
61 |
gr.inputs.Textbox(default="#ffffff", label="Background Color (Hex Code)"),
|
62 |
-
gr.inputs.Slider(minimum=0, maximum=100, step=10, default=0, label="Crop Top (
|
63 |
-
gr.inputs.Slider(minimum=0, maximum=100, step=10, default=0, label="Crop Bottom (
|
64 |
],
|
65 |
outputs=[gr.outputs.Image(type="numpy", label="Result"), gr.outputs.Text(label="Image Info")],
|
66 |
title="Image Resizer",
|
67 |
-
description="Reduce the size of an image, overlay it on a colored background, shift it, and crop the top and/or bottom."
|
68 |
)
|
69 |
|
70 |
if __name__ == "__main__":
|
71 |
-
iface.launch()
|
|
|
10 |
# Convert the hex code to RGB
|
11 |
return tuple(int(hex_code[i:i+2], 16) for i in (0, 2, 4))
|
12 |
|
13 |
+
def resize_and_overlay_image(input_image, reduction_percentage, shift_pixels, shift_pixels_ud, background_color, crop_top_percentage, crop_bottom_percentage):
|
14 |
# Check if the input image is empty
|
15 |
if input_image.size == 0:
|
16 |
return None
|
|
|
24 |
# Get the image dimensions
|
25 |
height, width = img.shape[:2]
|
26 |
|
27 |
+
# Calculate the number of pixels to crop from the top and bottom as a percentage of the image height
|
28 |
+
crop_top = int(height * crop_top_percentage / 100)
|
29 |
+
crop_bottom = int(height * crop_bottom_percentage / 100)
|
30 |
+
|
31 |
# Crop the top and/or bottom of the image
|
32 |
img = img[crop_top:height - crop_bottom, :]
|
33 |
|
|
|
63 |
gr.inputs.Slider(minimum=-150, maximum=150, step=10, default=0, label="Shift Pixels Left / Right"),
|
64 |
gr.inputs.Slider(minimum=-150, maximum=250, step=10, default=0, label="Shift Pixels Up / Down"),
|
65 |
gr.inputs.Textbox(default="#ffffff", label="Background Color (Hex Code)"),
|
66 |
+
gr.inputs.Slider(minimum=0, maximum=100, step=10, default=0, label="Crop Top (%)"),
|
67 |
+
gr.inputs.Slider(minimum=0, maximum=100, step=10, default=0, label="Crop Bottom (%)")
|
68 |
],
|
69 |
outputs=[gr.outputs.Image(type="numpy", label="Result"), gr.outputs.Text(label="Image Info")],
|
70 |
title="Image Resizer",
|
71 |
+
description="Reduce the size of an image, overlay it on a colored background, shift it, and crop the top and/or bottom as a percentage."
|
72 |
)
|
73 |
|
74 |
if __name__ == "__main__":
|
75 |
+
iface.launch()
|