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 image serializing - REF-1889 #2550

Merged

Conversation

mentally-gamez-soft
Copy link
Contributor

@mentally-gamez-soft mentally-gamez-soft commented Feb 7, 2024

All Submissions:

  • Have you followed the guidelines stated in CONTRIBUTING.md file?
  • Have you checked to ensure there aren't any other open Pull Requests for the desired changed?

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

New Feature Submission:

  • Does your submission pass the tests?
  • Have you linted your code locally prior to submission?

Changes To Core Features:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your core changes, as applicable?
  • Have you successfully ran tests with your changes locally?

After these steps, you're ready to open a pull request.

a. Give a descriptive title to your PR.  Issue REF-1889 - Invesatigate PIL Image serialization

b. Describe your changes. -|>  utils/serializers.py  there is no such thing as a format_mimetype property in an image object

c. Put `closes #XXXX` in your comment to auto-close the issue that your PR fixes (if such). 

@@ -319,7 +319,7 @@ def serialize_image(image: Img) -> str:
image.save(buff, format=getattr(image, "format", None) or "PNG")
image_bytes = buff.getvalue()
base64_image = base64.b64encode(image_bytes).decode("utf-8")
mime_type = getattr(image, "get_format_mimetype", lambda: "image/png")()
mime_type = getattr(image, "get_format", lambda: "image/png")()
Copy link
Collaborator

Choose a reason for hiding this comment

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

i don't think get_format is actually valid here... when i examine the resulting mime_type, it comes out as image/png, even thought the image is actually a jpeg

Throw a warning if the image format does not have an associated MIME type and
ultimately fallback to image/png and let the browser figure it out.
@masenf masenf merged commit 278183b into reflex-dev:main Feb 22, 2024
44 of 45 checks passed
Yummy-Yums pushed a commit to Yummy-Yums/reflex-codebase that referenced this pull request Feb 28, 2024
* fix image serializing

* If get_format_mimetype does not work, look up format in Image.MIME

Throw a warning if the image format does not have an associated MIME type and
ultimately fallback to image/png and let the browser figure it out.

* test_media: end to end serialization of PIL images

---------

Co-authored-by: Masen Furer <[email protected]>
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.

3 participants