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

Fix ImageEditor Size Issues #10357

Merged
merged 23 commits into from
Jan 22, 2025
Merged

Conversation

freddyaboulton
Copy link
Collaborator

@freddyaboulton freddyaboulton commented Jan 15, 2025

Description

Closes: #7685
Closes: #8667
Closes: #10265
Closes: #10255
Closes: #9889
Closes: #9305
Closes: #8556

Fixes the image editor sizing issues by taking the following approach:

  • If canvas_size=None (default) the canvas size is determined by the background image.
  • If canvas_size is givem, then images are resized to fit within this canvas size while keeping their original aspect ratio.
  • Adds a new fixed_canvas parameter. If fixed_canvas is True, then the canvas size will not change to match the resized image. The resized image will be centered in the larger canvas. This should support some outpainting demos. See example below.
  • Dynamically changes the block height to fit the canvas. Before we were setting a block height of 450px but a default canvas size of 600px. So if the devicePixelRatio of the browser was less than two, the toolbar would pop out of the block after an image upload.
  • Adds appropriate e2e tests

Example of uploading a 256 x 256 image to a image editor with canvas_size=(500, 500), fixed_canvas=True
image

🎯 PRs Should Target Issues

Before your create a PR, please check to see if there is an existing issue for this change. If not, please create an issue before you create this PR, unless the fix is very small.

Not adhering to this guideline will result in the PR being closed.

Testing and Formatting Your Code

  1. PRs will only be merged if tests pass on CI. We recommend at least running the backend tests locally, please set up your Gradio environment locally and run the backed tests: bash scripts/run_backend_tests.sh

  2. Please run these bash scripts to automatically format your code: bash scripts/format_backend.sh, and (if you made any changes to non-Python files) bash scripts/format_frontend.sh

@gradio-pr-bot
Copy link
Collaborator

gradio-pr-bot commented Jan 15, 2025

🪼 branch checks and previews

Name Status URL
Spaces ready! Spaces preview
Website building...
Storybook ready! Storybook preview
🦄 Changes detected! Details

Install Gradio from this PR

pip install https://gradio-pypi-previews.s3.amazonaws.com/9d27e43d5aa44ecfb6df0f2d7540e767c55b52b5/gradio-5.12.0-py3-none-any.whl

Install Gradio Python Client from this PR

pip install "gradio-client @ git+https://github.com/gradio-app/gradio@9d27e43d5aa44ecfb6df0f2d7540e767c55b52b5#subdirectory=client/python"

Install Gradio JS Client from this PR

npm install https://gradio-npm-previews.s3.amazonaws.com/9d27e43d5aa44ecfb6df0f2d7540e767c55b52b5/gradio-client-1.10.0.tgz

Use Lite from this PR

<script type="module" src="https://gradio-lite-previews.s3.amazonaws.com/9d27e43d5aa44ecfb6df0f2d7540e767c55b52b5/dist/lite.js""></script>

@gradio-pr-bot
Copy link
Collaborator

gradio-pr-bot commented Jan 15, 2025

🦄 change detected

This Pull Request includes changes to the following packages.

Package Version
@gradio/imageeditor patch
gradio patch
  • Maintainers can select this checkbox to manually select packages to update.

With the following changelog entry.

Fix ImageEditor Size Issues

Maintainers or the PR author can modify the PR title to modify this entry.

Something isn't right?

  • Maintainers can change the version label to modify the version bump.
  • If the bot has failed to detect any changes, or if this pull request needs to update multiple packages to different versions or requires a more comprehensive changelog entry, maintainers can update the changelog file directly.

@freddyaboulton freddyaboulton marked this pull request as ready for review January 15, 2025 16:36
@freddyaboulton freddyaboulton requested a review from pngwn January 15, 2025 16:36
@freddyaboulton freddyaboulton force-pushed the image-editor-disappearing-tools branch from a5b1b83 to bece029 Compare January 15, 2025 22:21
@pngwn
Copy link
Member

pngwn commented Jan 16, 2025

Just a quick question, this looks like a pretty significant breaking change as previously the crop_size was used to force constraints while the canvas_size was just an initial value, this will cause breakages for existing apps.

How do we want to handle this?

@pngwn pngwn mentioned this pull request Jan 16, 2025
16 tasks
@freddyaboulton
Copy link
Collaborator Author

Yea it's a good point. But I think the change in behavior is more of a bug fix and it's complimentary to the crop_size parameter instead of replacing it.

What I gathered from the issues is that people find the current canvas size behavior confusing. I think developers find it more natural to control the canvas size via canvas_size as opposed to crop_size. The new resize mechanic in canvas_size also preserves the entire contents of the image which may be preferred for some cases but the existing crop_size constraints are useful when an actual crop is desired.

Copy link
Member

@pngwn pngwn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Thanks @freddyaboulton!

@freddyaboulton freddyaboulton enabled auto-merge (squash) January 22, 2025 15:18
@freddyaboulton freddyaboulton merged commit 43e7cce into main Jan 22, 2025
22 of 23 checks passed
@freddyaboulton freddyaboulton deleted the image-editor-disappearing-tools branch January 22, 2025 18:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment