簡化合併
This commit is contained in:
		
							
								
								
									
										6
									
								
								pp.py
									
									
									
									
									
								
							
							
						
						
									
										6
									
								
								pp.py
									
									
									
									
									
								
							@@ -54,13 +54,15 @@ def download_image(url: str, max_size=32767) -> Image.Image:
 | 
				
			|||||||
            else:
 | 
					            else:
 | 
				
			||||||
                print(f'从OSS下载图片 {url}')
 | 
					                print(f'从OSS下载图片 {url}')
 | 
				
			||||||
                oss_auth = oss2.Auth(config['OSS_ACCESS_KEY_ID'], config['OSS_ACCESS_KEY_SECRET'])
 | 
					                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:
 | 
					        else:
 | 
				
			||||||
 | 
					            print(f'从网络下载图片 {url}')
 | 
				
			||||||
            response = requests.get(url)
 | 
					            response = requests.get(url)
 | 
				
			||||||
            img = Image.open(io.BytesIO(response.content))
 | 
					            img = Image.open(io.BytesIO(response.content))
 | 
				
			||||||
        if img.mode != 'RGB':
 | 
					        if img.mode != 'RGB':
 | 
				
			||||||
            img = img.convert('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}')
 | 
					            print(f'跳过尺寸过大的图像 {url}')
 | 
				
			||||||
            return None
 | 
					            return None
 | 
				
			||||||
        return img
 | 
					        return img
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user