创建 pictures_handle.py
parent
f82c7db414
commit
9233f0224d
|
|
@ -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
|
||||||
Loading…
Reference in New Issue