From cbcbc6489982b1046315d21ba73ff906f2d056c8 Mon Sep 17 00:00:00 2001 From: satori Date: Sun, 3 Dec 2023 17:40:29 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86=E4=B8=8D=E6=98=AF=E4=B8=89=E9=80=9A?= =?UTF-8?q?=E9=81=93=E7=9A=84=E5=9B=BE=E5=83=8F=E8=BD=AC=E6=8D=A2=E4=B8=BA?= =?UTF-8?q?=E4=B8=89=E9=80=9A=E9=81=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pp.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/pp.py b/pp.py index 2f266ea..5fe6d7d 100755 --- a/pp.py +++ b/pp.py @@ -36,14 +36,15 @@ def download_image(url: str) -> Image.Image: return None try: if url.startswith('http://image.gameuiux.cn/') or url.startswith('https://image.gameuiux.cn/'): - url = url.replace('http://image.gameuiux.cn/', - '').replace('https://image.gameuiux.cn/', '') - oss_auth = oss2.Auth( - config['OSS_ACCESS_KEY_ID'], config['OSS_ACCESS_KEY_SECRET']) - return Image.open(io.BytesIO(oss2.Bucket(oss_auth, f'http://{config["OSS_HOST"]}', config['OSS_BUCKET_NAME']).get_object(url).read())) + url = url.replace('http://image.gameuiux.cn/', '').replace('https://image.gameuiux.cn/', '') + oss_auth = oss2.Auth(config['OSS_ACCESS_KEY_ID'], config['OSS_ACCESS_KEY_SECRET']) + img = Image.open(io.BytesIO(oss2.Bucket(oss_auth, f'http://{config["OSS_HOST"]}', config['OSS_BUCKET_NAME']).get_object(url).read())) else: response = requests.get(url) - return Image.open(io.BytesIO(response.content)) + img = Image.open(io.BytesIO(response.content)) + if img.mode != 'RGB' + img = img.convert('RGB') + return img except Exception as e: print(f'图片从{url}下载失败,错误信息为:{e}') return None