Files
growth_report/utils/image_utils.py
2025-12-10 22:49:03 +08:00

29 lines
808 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import os
def find_image_path(folder, base_filename):
"""
在指定文件夹中查找图片,支持 jpg/jpeg/png 等多种后缀。
:param folder: 文件夹路径
:param base_filename: 基础文件名(不带后缀,例如 "1""me_image"
:return: 找到的完整文件路径,如果没找到则返回 None
"""
if not os.path.exists(folder):
return None
# 支持的后缀列表 (包含大小写)
extensions = [
".jpg", ".JPG",
".jpeg", ".JPEG",
".png", ".PNG",
".bmp", ".BMP"
]
for ext in extensions:
# 拼凑完整路径,例如 data/images/张三/1.png
full_path = os.path.join(folder, base_filename + ext)
if os.path.exists(full_path):
return full_path
return None