加入对本地文件的读取
This commit is contained in:
@@ -11,10 +11,7 @@ import requests
|
||||
|
||||
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
|
||||
from PIL import Image, ImageFile
|
||||
|
||||
ImageFile.LOAD_TRUNCATED_IMAGES = True
|
||||
|
||||
from PIL import Image
|
||||
from time import sleep
|
||||
from sqlalchemy import update
|
||||
from config.keys import PATIENT_NAME, ADMISSION_DATE, DISCHARGE_DATE, MEDICAL_EXPENSES, PERSONAL_CASH_PAYMENT, \
|
||||
@@ -38,12 +35,15 @@ from ucloud import ucloud
|
||||
|
||||
# 获取图片
|
||||
def open_image_from_url(url):
|
||||
# 发送HTTP请求获取图片数据
|
||||
response = requests.get(url)
|
||||
# 将响应内容转化为BytesIO对象,以便PIL处理
|
||||
image_stream = BytesIO(response.content)
|
||||
# 使用PIL的Image.open方法打开图像
|
||||
image = Image.open(image_stream)
|
||||
if url.startswith("http"):
|
||||
image = Image.open(url)
|
||||
else:
|
||||
# 发送HTTP请求获取图片数据
|
||||
response = requests.get(url)
|
||||
# 将响应内容转化为BytesIO对象,以便PIL处理
|
||||
image_stream = BytesIO(response.content)
|
||||
# 使用PIL的Image.open方法打开图像
|
||||
image = Image.open(image_stream)
|
||||
return image
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user