Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradio/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -1111,7 +1111,7 @@ def __init__(
"""
Parameters:
default_value(str): A path or URL for the default value that Image component is going to take.
shape (Tuple[int, int]): (width, height) shape to crop and resize image to; if None, matches input image size.
shape (Tuple[int, int]): (width, height) shape to crop and resize image to; if None, matches input image size. Pass None for either width or height to only crop and resize the other.
image_mode (str): "RGB" if color, or "L" if black and white.
invert_colors (bool): whether to invert the image as a preprocessing step.
source (str): Source of image. "upload" creates a box where user can drop an image file, "webcam" allows user to take snapshot from their webcam, "canvas" defaults to a white image that can be edited and drawn upon with tools.
Expand Down
11 changes: 9 additions & 2 deletions gradio/processing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ def resize_and_crop(img, size, crop_type="center"):
"""
Resize and crop an image to fit the specified size.
args:
size: `(width, height)` tuple.
size: `(width, height)` tuple. Pass `None` for either width or height
to only crop and resize the other.
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.
Expand All @@ -110,7 +111,13 @@ def resize_and_crop(img, size, crop_type="center"):
center = (0.5, 0.5)
else:
raise ValueError
return ImageOps.fit(img, size, centering=center)

resize = list(size)
if size[0] is None:
resize[0] = img.size[0]
if size[1] is None:
resize[1] = img.size[1]
return ImageOps.fit(img, resize, centering=center)


##################
Expand Down