Skip to content

fix image serializing - REF-1889#2550

Merged
masenf merged 4 commits intoreflex-dev:mainfrom
mentally-gamez-soft:fix-REF-1889-image-serializing
Feb 22, 2024
Merged

fix image serializing - REF-1889#2550
masenf merged 4 commits intoreflex-dev:mainfrom
mentally-gamez-soft:fix-REF-1889-image-serializing

Conversation

@mentally-gamez-soft
Copy link
Copy Markdown
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). 

Comment thread reflex/utils/serializers.py Outdated
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
Copy Markdown
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
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 <m_github@0x26.net>
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