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

Support PIL images as image source #2069

Merged
merged 2 commits into from
Nov 23, 2023
Merged

Support PIL images as image source #2069

merged 2 commits into from
Nov 23, 2023

Conversation

falkoschindler
Copy link
Contributor

@falkoschindler falkoschindler commented Nov 22, 2023

Following up on feature request #2067, this PR adds support for PIL images as source for ui.image and ui.interactive_image. Note that changing the image programmatically via value = ... or set_value(...) is handled as well.

I'm just not sure if this is the right approach, because we implicitly define the image format to be PNG, and I'm not sure if we benefit from ZIP compression when sending the image content as byte string instead of serving an image file instead.


  • make image format a static constant in ui.image.

@falkoschindler falkoschindler requested a review from rodja November 22, 2023 18:09
@falkoschindler falkoschindler added this to the 1.4.4 milestone Nov 22, 2023
@falkoschindler falkoschindler added the enhancement New feature or request label Nov 22, 2023
@nghia-vo
Copy link
Contributor

How to control the size of a displayed image? Something similar to ui.pyplot(figsize=)

@rodja
Copy link
Member

rodja commented Nov 23, 2023

we implicitly define the image format to be PNG

I think that is ok. Users needing JPEG or something else could use the image_to_base64 function instead of relying on the automatism.

and I'm not sure if we benefit from ZIP compression

Well, this suboptimal. Similar to ui.download the data is send through a websocket event which we do not compress. But that should be worth another pull request in my opinion.

How to control the size of a displayed image? Something similar to ui.pyplot(figsize=)

The physical size of the image can be changed by applying resize operations on the PIL Image before passing into ui.image. And the display size is controlled with css and Tailwind. No need for another parameter.

@falkoschindler falkoschindler self-assigned this Nov 23, 2023
@falkoschindler falkoschindler merged commit 59546fb into main Nov 23, 2023
@falkoschindler falkoschindler deleted the pil branch November 23, 2023 15:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants