from PIL import Image from data.path_constant import DOWNLOAD_DIR def get_missing_images(): for first_level_path in DOWNLOAD_DIR.iterdir(): if first_level_path.is_dir(): for second_level_path in first_level_path.iterdir(): if second_level_path.is_dir(): images = [] missing_images = [] for third_level_path in second_level_path.iterdir(): images.append(int(third_level_path.name.split('.')[0])) sorted_images = sorted(images, key=int) max_index = int(sorted_images[-1]) for i in range(2, max_index): if i not in images: missing_images.append(i) if len(missing_images) > 0: print(first_level_path.name) print(second_level_path.name) print(missing_images) def resize_and_overwrite(input_path, target_width): # 打开原始webp图像 with Image.open(input_path) as img: # 获取原始尺寸 width, height = img.size # 计算缩放后的高度,保持宽高比 target_height = int((target_width / width) * height) # 调整图像尺寸并保持比例 resized_img = img.resize((target_width, target_height), Image.Resampling.LANCZOS) # 直接覆盖原始文件保存为webp格式 resized_img.save(input_path, "WEBP") # 使用方法示例 # input_webp = "input_image.webp" # target_width = 720 # 设置目标宽度为720像素 # resize_and_overwrite(input_webp, target_width)