diff --git a/webmo/webmo_rest.py b/webmo/webmo_rest.py index d4b70df..a2587d9 100644 --- a/webmo/webmo_rest.py +++ b/webmo/webmo_rest.py @@ -706,45 +706,45 @@ async def _process_callback_response(self): return EmbeddedImage(data=decoded_image_data) +if has_ipython: + class EmbeddedImage(Image): + """The EmbeddedImage class is a IPython-displayable image object with additional functionality. -class EmbeddedImage(Image): - """The EmbeddedImage class is a IPython-displayable image object with additional functionality. + The EmbeddedImage class is a Jupyter-renderable image object, derived from IPython.display.image. + However, the EmbeddedImage also adds additional utility conversion methods. + """ + def __init__(self, data): + super().__init__(data) - The EmbeddedImage class is a Jupyter-renderable image object, derived from IPython.display.image. - However, the EmbeddedImage also adds additional utility conversion methods. - """ - def __init__(self, data): - super().__init__(data) + def save(self, filename): + """Saves the EmbeddedImage to disk as a PNG-formatted image. - def save(self, filename): - """Saves the EmbeddedImage to disk as a PNG-formatted image. + This call saves the EmbeddedImage object to disk as PNG-formatted image. - This call saves the EmbeddedImage object to disk as PNG-formatted image. + Arguments: + filename(str): The path to the target PNG file. A "png" extension is added, if not provided. - Arguments: - filename(str): The path to the target PNG file. A "png" extension is added, if not provided. + Returns: + None + """ + if not filename.endswith(".png"): + filename += ".png" + with open(filename, 'wb') as fp: + fp.write(self.data) - Returns: - None - """ - if not filename.endswith(".png"): - filename += ".png" - with open(filename, 'wb') as fp: - fp.write(self.data) + def to_pil_image(self): + """Returns an equivalent Pillow (PIL) Image object. - def to_pil_image(self): - """Returns an equivalent Pillow (PIL) Image object. + This call converts and returns and equivalent Pillow (PIL) Image representation of the + current EmbeddedImage object, for further manipulation. - This call converts and returns and equivalent Pillow (PIL) Image representation of the - current EmbeddedImage object, for further manipulation. + Arguments: + None - Arguments: - None - - Returns: - A Pillow PIL.Image.Image object. - """ - from PIL import Image - from io import BytesIO + Returns: + A Pillow PIL.Image.Image object. + """ + from PIL import Image + from io import BytesIO - return Image.open(BytesIO(self.data)) + return Image.open(BytesIO(self.data))