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 Apr 25, 2024
1 parent eae74bb commit b9ddbd0
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

Check failure on line 6 in microscope/microscope_info.py

View workflow job for this annotation

GitHub Actions / lint-test / lint-test

Ruff (F401)

microscope/microscope_info.py:6:8: F401 `base64` imported but unused
import io
from PIL import Image, ExifTags

Check failure on line 8 in microscope/microscope_info.py

View workflow job for this annotation

GitHub Actions / lint-test / lint-test

Ruff (F401)

microscope/microscope_info.py:8:24: F401 `PIL.ExifTags` imported but unused
from dotenv import load_dotenv
from custom_exceptions import MicroscopeQueryError, ExifNonPresentError

Check failure on line 10 in microscope/microscope_info.py

View workflow job for this annotation

GitHub Actions / lint-test / lint-test

Ruff (F401)

microscope/microscope_info.py:10:53: F401 `custom_exceptions.ExifNonPresentError` imported but unused
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 b9ddbd0

Please sign in to comment.