使用本地图像

This commit is contained in:
2024-11-10 17:37:14 +08:00
parent bd600ee153
commit a85f252010
2 changed files with 7 additions and 1 deletions

View File

@@ -13,6 +13,13 @@ def download_image(url:str) -> Image:
if url.startswith('http://image.gameuiux.cn/') or url.startswith('https://image.gameuiux.cn/'):
try:
url = url.replace('http://image.gameuiux.cn/', '').replace('https://image.gameuiux.cn/', '')
# 先尝试本地图像
if os.path.exists(f"oss/{url}"):
print('使用本地图像:', url)
return Image.open(f"{IMAGES_PATH}/{url}")
# 使用 OSS 下载
print('使用 OSS 下载:', url)
obj = bucket_image2.get_object(url).read()
return Image.open(io.BytesIO(obj))
except Exception: