155elkhorn commited on
Commit
28b8faf
·
1 Parent(s): 710870c

Update app.py

Browse files

Add crop option

Files changed (1) hide show
  1. app.py +9 -4
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,9 @@ 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
  # Calculate the new dimensions based on the reduction percentage
28
  new_height = int(height * reduction_percentage / 100)
29
  new_width = int(width * reduction_percentage / 100)
@@ -55,12 +58,14 @@ iface = gr.Interface(
55
  gr.inputs.Slider(minimum=0, maximum=100, step=10, default=80, label="Percentage of Original"),
56
  gr.inputs.Slider(minimum=-150, maximum=150, step=10, default=0, label="Shift Pixels Left / Right"),
57
  gr.inputs.Slider(minimum=-150, maximum=250, step=10, default=0, label="Shift Pixels Up / Down"),
58
- gr.inputs.Textbox(default="#ffffff", label="Background Color (Hex Code)")
 
 
59
  ],
60
  outputs=gr.outputs.Image(type="numpy", label="Result"),
61
  title="Image Resizer",
62
- description="Reduce the size of an image and overlay it on a colored background and shift it to the right."
63
  )
64
 
65
  if __name__ == "__main__":
66
- 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, crop_bottom):
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
+ # Crop the top and/or bottom of the image
28
+ img = img[crop_top:height - crop_bottom, :]
29
+
30
  # Calculate the new dimensions based on the reduction percentage
31
  new_height = int(height * reduction_percentage / 100)
32
  new_width = int(width * reduction_percentage / 100)
 
58
  gr.inputs.Slider(minimum=0, maximum=100, step=10, default=80, label="Percentage of Original"),
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 (pixels)"),
63
+ gr.inputs.Slider(minimum=0, maximum=100, step=10, default=0, label="Crop Bottom (pixels)")
64
  ],
65
  outputs=gr.outputs.Image(type="numpy", label="Result"),
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()