As discussed the gradio Image shape tuple should be able to set (width, None) or (None, height) for setting only a width or height for resize and crop operations and scale accordingly
|
def resize_and_crop(img, size, crop_type="center"): |
|
""" |
|
Resize and crop an image to fit the specified size. |
|
args: |
|
size: `(width, height)` tuple. |
|
crop_type: can be 'top', 'middle' or 'bottom', depending on this |
|
value, the image will cropped getting the 'top/left', 'middle' or |
|
'bottom/right' of the image to fit the size. |
|
raises: |
|
ValueError: if an invalid `crop_type` is provided. |
|
""" |
|
if crop_type == "top": |
|
center = (0, 0) |
|
elif crop_type == "center": |
|
center = (0.5, 0.5) |
|
else: |
|
raise ValueError |
|
return ImageOps.fit(img, size, centering=center) |
As discussed the gradio Image shape tuple should be able to set (width, None) or (None, height) for setting only a width or height for resize and crop operations and scale accordingly
gradio/gradio/processing_utils.py
Lines 96 to 113 in c9298b3