将不是三通道的图像转换为三通道
This commit is contained in:
		
							
								
								
									
										13
									
								
								pp.py
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								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
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user