gradio-app / gradio

Build and share delightful machine learning apps, all in Python. 🌟 Star to support our work!
http://www.gradio.app
Apache License 2.0
31.18k stars 2.33k forks source link

[ImageEditor] - Support resizing images without cropping #1451

Open hysts opened 2 years ago

hysts commented 2 years ago

Is your feature request related to a problem? Please describe.

I'd like an option to resize the input image to fit into the specified image size. In my understanding, currently, specifying shape in gradio.Image only supports center crop. In my use case, the input image needs to be small enough not to cause out of memory error, but I don't want the image to be cropped. I know I can work around this by adding a callback to Image that resizes image, but I think it'd be better if the library supported this in the first place, because I think it's more favorable behavior in many cases.

Describe the solution you'd like

Add a keyword argument to gradio.Image to allow specifying resizing method.

Additional context

I came across this issue when I was making this app. Here is a sample Space. The first row is the current behavior, but I prefer the behavior in the second row, which uses the workaround mentioned above.

omerXfaruq commented 2 years ago

Thx for another suggestion @hysts!

I personally think it is better for users to resize the image themselves. Because it is quite easy, and a use-case not really related to library imo. But could ask for @abidlabs and @pngwn's opinion on this.

hysts commented 2 years ago

@FarukOzderim Thanks for the reply. So, is the current workaround the recommended way to resize input images? I thought the shape argument of gradio.Image was for this kind of use case, but I may be misunderstanding...

This might be something I should have written in my first post, but, in the case of Hugging Face Spaces, if out of memory occurs, the Space crashes and needs to be restarted by its owner. So app creators need to implement resizing input images so that OOM won't occur because people who just want to try out apps deployed in Hugging Face Spaces don't want to resize images themselves.

omerXfaruq commented 2 years ago

Btw a different thought:

I am okay with having this feature in Gradio if it will work on the input component directly, ie.

User uploads the first image, but the cropped image shows in the input after user loads it, ie we crop the image while uploading and it is more transparent to the user.

image

pngwn commented 2 years ago

Resizing is planned as part of #466. However, I do not know when that work will be tackled. Will try to get an update.

abidlabs commented 1 year ago

Similar feedback here: https://github.com/gradio-app/gradio/issues/2054#issuecomment-1270216411