更新 pictures_handle.py
parent
8a16672573
commit
fc8976efba
|
|
@ -1,23 +1,34 @@
|
|||
import os
|
||||
|
||||
|
||||
def get_pictures_info(directory):
|
||||
def get_pictures_info(directory, page, page_size):
|
||||
pictures = []
|
||||
counter = 1
|
||||
start_index = (page - 1) * page_size
|
||||
end_index = start_index + page_size
|
||||
counter = 0
|
||||
|
||||
for filename in os.listdir(directory):
|
||||
# print(f"directory: {directory}")
|
||||
if filename.lower().endswith(('.png', '.jpg', '.jpeg', '.gif', '.bmp')):
|
||||
if start_index <= counter < end_index:
|
||||
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),
|
||||
"id": counter + 1,
|
||||
"photo_name": filename,
|
||||
"photo_size": round(size_mb, 2),
|
||||
"photo_url": file_path
|
||||
}
|
||||
pictures.append(picture_info)
|
||||
counter += 1
|
||||
if counter >= end_index:
|
||||
break
|
||||
return pictures
|
||||
|
||||
|
||||
def get_total_pages(directory, page_size):
|
||||
total_photos = 0
|
||||
for filename in os.listdir(directory):
|
||||
if filename.lower().endswith(('.png', '.jpg', '.jpeg', '.gif', '.bmp')):
|
||||
total_photos += 1
|
||||
return (total_photos + page_size - 1) // page_size
|
||||
|
|
|
|||
Loading…
Reference in New Issue