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

move array_to_imagestr function to be part of public API #2879

Merged
merged 3 commits into from
Nov 17, 2020

Conversation

emmanuelle
Copy link
Contributor

Solves #2863.

Now you can do
from plotly.utils import array_to_imagestr

However, plotly.utils is not a subpackage but just a module so it does not appear in the API doc. It'd be easy to change this to use a subpackage like what was done for plotly.colors when working on the API doc. One the other hand it's enough for me if the function appears in image-related docs of plotly.py and dash so I won't push hard for this change.

pil_imported = False


def array_to_imagestr(img, backend="pil", compression=4, ext="png"):
Copy link
Contributor

Choose a reason for hiding this comment

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

the name here is maybe something to think about? technically what we are doing here is representing an image array as a data URI so I would vote for something like image_array_to_data_url ?



def array_to_imagestr(img, backend="pil", compression=4, ext="png"):
"""Converts a numpy array of uint8 into a base64 png string.
Copy link
Contributor

Choose a reason for hiding this comment

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

docstring nit: this isn't always PNG now :)

@nicolaskruchten
Copy link
Contributor

💃

@emmanuelle emmanuelle merged commit 9c9b98e into master Nov 17, 2020
@emmanuelle emmanuelle deleted the image-string-util branch December 1, 2020 13:45
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.

2 participants