From 16163e42c0c30d42147d8553c4c20dcec918fafe Mon Sep 17 00:00:00 2001 From: satori Date: Tue, 19 Nov 2024 15:36:01 +0800 Subject: [PATCH] =?UTF-8?q?=E7=B0=A1=E5=8C=96=E5=90=88=E4=BD=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pp.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pp.py b/pp.py index eb1d72f..dd6a41d 100755 --- a/pp.py +++ b/pp.py @@ -54,13 +54,15 @@ def download_image(url: str, max_size=32767) -> Image.Image: else: print(f'从OSS下载图片 {url}') 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())) + bucket = oss2.Bucket(oss_auth, f'http://{config["OSS_HOST"]}', config['OSS_BUCKET_NAME']) + img = Image.open(io.BytesIO(bucket.get_object(url).read())) else: + print(f'从网络下载图片 {url}') response = requests.get(url) img = Image.open(io.BytesIO(response.content)) if img.mode != 'RGB': img = img.convert('RGB') - if img.size[0] > max_size or img.size[1] > max_size: + if max(img.size) > max_size: print(f'跳过尺寸过大的图像 {url}') return None return img