diff --git a/utils/pictures_handle.py b/utils/pictures_handle.py new file mode 100644 index 0000000..c4ffa4c --- /dev/null +++ b/utils/pictures_handle.py @@ -0,0 +1,23 @@ +import os + + +def get_pictures_info(directory): + pictures = [] + counter = 1 + + for filename in os.listdir(directory): + # print(f"directory: {directory}") + if filename.lower().endswith(('.png', '.jpg', '.jpeg', '.gif', '.bmp')): + file_path = os.path.join(directory, filename) + size = os.path.getsize(file_path) + size_mb = size / (1024 * 1024) + photo_name = filename + picture_info = { + "id": counter, + "photo_name": photo_name, + "photo_size": round(size_mb,2), + "photo_url": file_path + } + pictures.append(picture_info) + counter += 1 + return pictures