Added decoding for base64-encoded images #88
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Right now, Image types accept a binary bytes object and return a base64-encoded HTML representation of the image suitable for embedding in an HTML document. Some packages like Datashader return such a bytes object from their
_repr_png_()
methods, which works well, but other_repr_png_
methods like the ones innxpd
return a string already base64 encoded. With this PR, if a string is provided as the image data, Panel will base64-decode the string before moving on; it will later be base64 encoded again. This double decoding and subsequent re-encoding isn't optimal, but it's a simple fix for not being able to view such objects.The code uses
isinstance(...,str)
to check for the string, which seems safe for py2/py3 because a base64-encoded string should not normally be unicode on either Python version.