image_to_data_url

image_to_data_url(location, data_format=None, return_data_format=False)

Convert an image file or URL to a data URL with base64 encoded data.

Parameters
  • data (str) – Filepath or URL of an image.

  • data_format (str, optional) – By default, the format of the image data is guessed from the file or URL ending of the location argument, or if that fails, from features of the binary data. Alternatively, the format can be passed explicitly with this argument, so no potentially incorrect guessing has to be done.

  • return_data_format (bool) – If True, the given or detected data format is returned in addition to the data url.

Returns

data_url (str) – URL with image data embedded inside it in form of text that represents base64 encoded binary data.

References