创建 pictures_handle.py

master
wangsiyuan 2024-01-23 18:02:54 +08:00
parent f82c7db414
commit 9233f0224d
1 changed files with 23 additions and 0 deletions

23
utils/pictures_handle.py Normal file
View File

@ -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