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

save buffer to PNG format instead #5

Merged
merged 2 commits into from
Jun 13, 2023

Conversation

dangkhoasdc
Copy link
Contributor

If the input image is a PNG file with the 'Alpha' channel, PIL could not save it as "JPG" format:

OSError: cannot write mode RGBA as JPEG

(Source: https://stackoverflow.com/questions/48248405/cannot-write-mode-rgba-as-jpeg )

To fix it, we can change the format of buffer when saving to 'PNG' instead. It can handle both 3-channel and 4-channel images. It also aligns with the format when we encode to base64 string.

@blackary
Copy link
Owner

Thanks!

@blackary blackary self-requested a review June 13, 2023 14:18
Copy link
Owner

@blackary blackary left a comment

Choose a reason for hiding this comment

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

Added a demo page -- works great!

@blackary blackary merged commit 98db3ab into blackary:main Jun 13, 2023
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.

None yet

2 participants