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

Serialize BufferedImages as base64 #694

Merged
merged 9 commits into from
May 16, 2024
Merged

Serialize BufferedImages as base64 #694

merged 9 commits into from
May 16, 2024

Conversation

ermolenkodev
Copy link
Contributor

@ermolenkodev ermolenkodev commented May 10, 2024

Fixes #675

This commit introduces toBase64() and encodeGzip() methods for ByteArray and image resizing methods for BufferedImage.
The commit introduces an ImageEncodingOptions class which controls how images are encoded when serializing a DataFrame to JSON with metadata. These options include whether to encode images as Base64, a size limit for resizing images, and an optional GZIP compression.
The default kotlin kernel renderer in the Kotlin Notebook plugin serializes images in their original dimensions, potentially causing an OOM exception. This commit overrides the default renderer to prevent such issues.
@Jolanrensen Jolanrensen changed the title Fix #675 Serialize BufferedImages as base64 May 13, 2024
* Refactored image encoding logic for DataFrame serialization.
* Removed custom renderer for buffered images as it affects rendering of single image objects
Introduced a configuration option to conditionally downsize BufferedImages in the HTML renderer. This mitigates potential memory problems by resizing images according to the provided DisplayConfiguration, specifically affecting the output of dataframes in the Kotlin Notebook plugin.
This commit introduces ImageSerializationTests for validating image base64 encoding. Additionally, a utility function has been added to Utils.kt to parse string into JsonObject for tests.
@ermolenkodev ermolenkodev marked this pull request as ready for review May 15, 2024 09:42
Developed a mechanism to enable or disable ImageViewer based on the current IDE version in the JupyterHtmlRenderer.
Copy link
Collaborator

@koperagen koperagen left a comment

Choose a reason for hiding this comment

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

Looks good, thank you!

In the ImageSerializationTests class, the method 'checkImagesEncodedAsStrings' has been renamed to 'checkImagesEncodedAsToString'.
@ermolenkodev ermolenkodev merged commit 60c4f28 into master May 16, 2024
2 checks passed
@ermolenkodev ermolenkodev deleted the fix-675 branch May 16, 2024 14:39
Copy link
Collaborator

Choose a reason for hiding this comment

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

@ermolenkodev wow these tests are very heavy! It takes my laptop about 2 full minutes to run just these ones.
image

Could you make the images like waaay smaller? Like 0.5KB or smaller instead of 2-4MB?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Serialize BufferedImages as base64
3 participants