def to_image_url(array, fmt='png', mode="data", quality=70, domain=None): supported_modes = ("data") if mode not in supported_modes: message = "Unsupported mode '%s', should be one of '%s'." raise ValueError(message, mode, supported_modes) image_data = serialize_array(array, fmt=fmt, quality=quality) base64_byte_string = base64.b64encode(image_data).decode('ascii') return base64_byte_string
def image(array, domain=None, w=None, format='png', **kwargs): """Display an image. Args: array: NumPy array representing the image fmt: Image format e.g. png, jpeg domain: Domain of pixel values, inferred from min & max values if None w: width of output image, scaled using nearest neighbor interpolation. size unchanged if None """ image_data = serialize_array(array, fmt=format, domain=domain) image = IPython.display.Image(data=image_data, format=format, width=w) IPython.display.display(image)
def _image_url(array, fmt='png', mode="data", quality=90, domain=None): """Create a data URL representing an image from a PIL.Image. Args: image: a numpy mode: presently only supports "data" for data URL Returns: URL representing image """ supported_modes = ("data") if mode not in supported_modes: message = "Unsupported mode '%s', should be one of '%s'." raise ValueError(message, mode, supported_modes) image_data = serialize_array(array, fmt=fmt, quality=quality) base64_byte_string = base64.b64encode(image_data).decode('ascii') return "data:image/" + fmt.upper() + ";base64," + base64_byte_string