Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Canvas drawing is cut off when the shape is explicitly set to be a square #3166

Closed
1 task done
Tracked by #466
lllyasviel opened this issue Feb 10, 2023 · 3 comments · Fixed by #3277
Closed
1 task done
Tracked by #466

Canvas drawing is cut off when the shape is explicitly set to be a square #3166

lllyasviel opened this issue Feb 10, 2023 · 3 comments · Fixed by #3277
Assignees
Labels
bug Something isn't working 🖼️ image Image component

Comments

@lllyasviel
Copy link

lllyasviel commented Feb 10, 2023

  • I have searched to see if a similar issue already exists.

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

Right now if we want to make a 512*512 drawing canvas, the only method is (1) ask users to create a pure white 512*512 image using third-party software like PhotoShop, then (2) ask users to import that blank image into gr.Image(source='upload', tool='sketch'), then (3) use the resulting mask as the user drawing for any applications. (Besides, the initial width of scribble can not be set by code.)

This is over-complicated. We should have an one-line function to make a simple drawing canvas.

Describe the solution you'd like

We may consider something like

gr.Image(source='blank', tool='sketch', size=(512, 512))

@abidlabs
Copy link
Member

Hi @lllyasviel this is already possible by doing:

gr.Image(source="canvas", shape=(512, 512))

For example, you can test this with this Blocks demo:

import gradio as gr

with gr.Blocks() as demo:
    i = gr.Image(source="canvas", shape=(512, 512))
    o = gr.Image()
    i.change(lambda x:x, i, o)

demo.launch()

@lllyasviel
Copy link
Author

@abidlabs
No. Right now gradio does not support a simple 512*512 drawing canvas.

pip install --upgrade gradio

then

image

Then the result will be like

image

As we can see, this has nothing to do with "shape=(512, 512)", the shape parameter does not control the resolution, it controls a "gradio-style dpi". You can even draw in this long rectangular:

image

When it is processed, the results provide strong evidence that "shape" is related to dpi and cropping, not shape of canvas

image

If this is an intentional design, it may be worthwhile to reopen this issue to target a more straightforward drawing board.

@abidlabs
Copy link
Member

Hi @lllyasviel so to achieve what you want, I think we need to do control both the image resolution (with is controlled via the shape parameter above) and the display size of the Image component, which is controlled via the .style() method of the Image component. I agree that it's a bit confusing, but I think this should achieve what you want:

import gradio as gr

with gr.Blocks() as demo:
    i = gr.Image(source="canvas", shape=(512, 512)).style(width=512, height=512)
    o = gr.Image().style(width=512, height=512)
    i.change(lambda x:x, i, o)

demo.launch()

However, when I tested this, I got the canvas being cut off at the halfway point, preventing me from drawing in the bottom half of the canvas, which is very strange.

image

I'm going to reopen this issue so that we can fix this. cc @pngwn

@abidlabs abidlabs reopened this Feb 10, 2023
@abidlabs abidlabs changed the title A simple 512*512 sketch drawing aera Canvas drawing is cut off when the shape is explicitly set to be a square Feb 10, 2023
@abidlabs abidlabs added the bug Something isn't working label Feb 10, 2023
@pngwn pngwn self-assigned this Feb 21, 2023
pngwn added a commit that referenced this issue Feb 22, 2023
@pngwn pngwn mentioned this issue Feb 22, 2023
7 tasks
@pngwn pngwn added the 🖼️ image Image component label Feb 22, 2023
@pngwn pngwn mentioned this issue Feb 22, 2023
20 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working 🖼️ image Image component
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants