From 9233f0224d8c6a09eab448ef60367c06418be8cf Mon Sep 17 00:00:00 2001 From: wangsiyuan <2392948297@qq.com> Date: Tue, 23 Jan 2024 18:02:54 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9B=E5=BB=BA=20pictures=5Fhandle.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/pictures_handle.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 utils/pictures_handle.py 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