Skip to content

Commit

Permalink
fixes #29: Add element to collect exiftags
Browse files Browse the repository at this point in the history
commit this change to not lose them to codespaces repo ending
  • Loading branch information
Maxence Guindon committed Mar 4, 2024
1 parent 6758682 commit bd820ad
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
20 changes: 15 additions & 5 deletions microscope/microscope_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_microscope_info.py
Original file line number Diff line number Diff line change
@@ -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)
Expand Down

0 comments on commit bd820ad

Please sign in to comment.