簡化合併

This commit is contained in:
2024-11-19 15:36:01 +08:00
parent 4465f1f9f0
commit 16163e42c0

6
pp.py
View File

@@ -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