🐛 Bug: Fix the bug where the Pillow dependency is not installed
Browse files- request.py +19 -19
request.py
CHANGED
|
@@ -51,25 +51,25 @@ async def get_encode_image(image_url):
|
|
| 51 |
os.remove(image_path)
|
| 52 |
return base64_image
|
| 53 |
|
| 54 |
-
from PIL import Image
|
| 55 |
-
import io
|
| 56 |
-
def validate_image(image_data, image_type):
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
|
| 74 |
async def get_image_message(base64_image, engine = None):
|
| 75 |
if base64_image.startswith("http"):
|
|
|
|
| 51 |
os.remove(image_path)
|
| 52 |
return base64_image
|
| 53 |
|
| 54 |
+
# from PIL import Image
|
| 55 |
+
# import io
|
| 56 |
+
# def validate_image(image_data, image_type):
|
| 57 |
+
# try:
|
| 58 |
+
# decoded_image = base64.b64decode(image_data)
|
| 59 |
+
# image = Image.open(io.BytesIO(decoded_image))
|
| 60 |
+
|
| 61 |
+
# # 检查图片格式是否与声明的类型匹配
|
| 62 |
+
# # print("image.format", image.format)
|
| 63 |
+
# if image_type == "image/png" and image.format != "PNG":
|
| 64 |
+
# raise ValueError("Image is not a valid PNG")
|
| 65 |
+
# elif image_type == "image/jpeg" and image.format not in ["JPEG", "JPG"]:
|
| 66 |
+
# raise ValueError("Image is not a valid JPEG")
|
| 67 |
+
|
| 68 |
+
# # 如果没有异常,则图片有效
|
| 69 |
+
# return True
|
| 70 |
+
# except Exception as e:
|
| 71 |
+
# print(f"Image validation failed: {str(e)}")
|
| 72 |
+
# return False
|
| 73 |
|
| 74 |
async def get_image_message(base64_image, engine = None):
|
| 75 |
if base64_image.startswith("http"):
|