From bd820addb2dc04169f60f6592cbe0d76b52cd554 Mon Sep 17 00:00:00 2001 From: Maxence Guindon Date: Mon, 4 Mar 2024 14:25:52 +0000 Subject: [PATCH] fixes #29: Add element to collect exiftags commit this change to not lose them to codespaces repo ending --- microscope/microscope_info.py | 20 +++++++++++++++----- tests/test_microscope_info.py | 2 +- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/microscope/microscope_info.py b/microscope/microscope_info.py index 4ec75474..ad857b5d 100644 --- a/microscope/microscope_info.py +++ b/microscope/microscope_info.py @@ -3,6 +3,8 @@ import uuid import logging import requests +import base64 +import io from PIL import Image, ExifTags from dotenv import load_dotenv from custom_exceptions import MicroscopeQueryError, ExifNonPresentError @@ -81,19 +83,27 @@ def get_microscope_configuration(METHODS): return config -def get_picture_details(path:str) -> dict: +def get_picture_details(image:bytes) -> dict: # Source 1 : https://thepythoncode.com/article/extracting-image-metadata-in-python # Source 2 : https://www.geeksforgeeks.org/how-to-extract-image-metadata-in-python/ ''' Retrieve exif details from picture. ''' - img = Image.open(path) - full_exif = { ExifTags.TAGS[k]: v for k, v in img._getexif().items() if k in ExifTags.TAGS } - return full_exif - + io_byte_image = io.BytesIO(image) + io_byte_image.seek(0) + + img = Image.open(io_byte_image) + file = ".".join(["picture_test", "png"]) + img.save(file) + + # img = Image.open(path) + + # full_exif = { ExifTags.TAGS[k]: v for k, v in img._getexif().items() if k in ExifTags.TAGS } + # return full_exif + if __name__ == "__main__": try: config = get_microscope_configuration(METHODS) diff --git a/tests/test_microscope_info.py b/tests/test_microscope_info.py index 244139ef..a41cbc39 100644 --- a/tests/test_microscope_info.py +++ b/tests/test_microscope_info.py @@ -1,6 +1,6 @@ import microscope.microscope_info as m -path=r"/workspaces/nachet-backend/docs/asssets/image/WIN_20240131_10_23_04_Pro.jpg" +path=r"/workspaces/nachet-backend/docs/asssets/image/test_02.jpg" def test_print_exif_info(): data = m.get_picture_details(path)