Skip to content

gradio Image shape None for width or height #768

@AK391

Description

@AK391

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)

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions