Spaces:
Sleeping
Sleeping
add position bottom and top
Browse files
app.py
CHANGED
|
@@ -39,10 +39,24 @@ def change_size(image, selected_size, size_align):
|
|
| 39 |
dominant_color = get_dominant_color(image)
|
| 40 |
|
| 41 |
new_image = Image.new("RGB", target_size, dominant_color)
|
| 42 |
-
|
| 43 |
-
#
|
| 44 |
-
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
new_image.paste(image, (x_offset, y_offset))
|
| 48 |
|
|
@@ -55,7 +69,7 @@ def gradio_interface():
|
|
| 55 |
image_input = gr.Image(type="pil", label="Upload Image")
|
| 56 |
size_input = gr.Dropdown(list(size_options.keys()), label="Size Options")
|
| 57 |
with gr.Row():
|
| 58 |
-
size_alignment = gr.Radio(["Left", "Center", "Right"], value="Center", label="Size Alignment")
|
| 59 |
image_output = gr.Image(type="pil", label="Resized Image with Background")
|
| 60 |
submit_button = gr.Button("Resize Image")
|
| 61 |
|
|
|
|
| 39 |
dominant_color = get_dominant_color(image)
|
| 40 |
|
| 41 |
new_image = Image.new("RGB", target_size, dominant_color)
|
| 42 |
+
|
| 43 |
+
# size allignment position left, right, and center
|
| 44 |
+
|
| 45 |
+
if size_align == "Left":
|
| 46 |
+
x_offset = 0
|
| 47 |
+
elif size_align == "Right":
|
| 48 |
+
x_offset = target_size[0] - image.width
|
| 49 |
+
else:
|
| 50 |
+
x_offset = (target_size[0] - image.width) // 2
|
| 51 |
+
|
| 52 |
+
# size allignment position top, bottom, and center
|
| 53 |
+
|
| 54 |
+
if size_align == "Top":
|
| 55 |
+
y_offset = 1
|
| 56 |
+
elif size_align == "Bottom":
|
| 57 |
+
y_offset = target_size[1] - image.width
|
| 58 |
+
else:
|
| 59 |
+
y_offset = (target_size[1] - image.width) // 2
|
| 60 |
|
| 61 |
new_image.paste(image, (x_offset, y_offset))
|
| 62 |
|
|
|
|
| 69 |
image_input = gr.Image(type="pil", label="Upload Image")
|
| 70 |
size_input = gr.Dropdown(list(size_options.keys()), label="Size Options")
|
| 71 |
with gr.Row():
|
| 72 |
+
size_alignment = gr.Radio(["Left", "Center", "Right", "Top", "Bottom"], value="Center", label="Size Alignment")
|
| 73 |
image_output = gr.Image(type="pil", label="Resized Image with Background")
|
| 74 |
submit_button = gr.Button("Resize Image")
|
| 75 |
|