diff --git a/src/ansys/dynamicreporting/core/utils/report_utils.py b/src/ansys/dynamicreporting/core/utils/report_utils.py index d433f1a1..88b25cb5 100644 --- a/src/ansys/dynamicreporting/core/utils/report_utils.py +++ b/src/ansys/dynamicreporting/core/utils/report_utils.py @@ -266,8 +266,8 @@ def image_to_data(img): if has_enve: # pragma: no cover if isinstance(img, enve.image): data = dict(width=img.dims[0], height=img.dims[1]) - if img.enhanced: - with tempfile.TemporaryDirectory() as temp_dir: + with tempfile.TemporaryDirectory() as temp_dir: + if img.enhanced: path = os.path.join(temp_dir, "enhanced_image.tif") # Save the image as a tiff file (enhanced) if img.save(path, options="Compression Deflate") == 0: @@ -279,6 +279,14 @@ def image_to_data(img): return data except OSError: return None + else: + path = os.path.join(temp_dir, "image.png") + if img.save(path) == 0: + try: + with open(path, "rb") as img_file: + return PIL_image_to_data(img_file.read()) + except OSError: + return None if not data: return PIL_image_to_data(img)