mirror of
https://github.com/zhayujie/chatgpt-on-wechat.git
synced 2026-07-21 14:17:11 +08:00
Support images in webp format.
This commit is contained in:
@@ -9,7 +9,6 @@ import json
|
|||||||
import os
|
import os
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
import uuid
|
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
from bridge.context import *
|
from bridge.context import *
|
||||||
@@ -297,9 +296,7 @@ def _convert_webp_to_png(webp_image):
|
|||||||
webp_image.seek(0)
|
webp_image.seek(0)
|
||||||
img = Image.open(webp_image).convert("RGBA")
|
img = Image.open(webp_image).convert("RGBA")
|
||||||
png_image = io.BytesIO()
|
png_image = io.BytesIO()
|
||||||
unique_filename = f"{uuid.uuid4()}.png"
|
|
||||||
img.save(png_image, format="PNG")
|
img.save(png_image, format="PNG")
|
||||||
png_image.name = unique_filename
|
|
||||||
png_image.seek(0)
|
png_image.seek(0)
|
||||||
return png_image
|
return png_image
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ class Keyword(Plugin):
|
|||||||
reply_text = self.keyword[content]
|
reply_text = self.keyword[content]
|
||||||
|
|
||||||
# 判断匹配内容的类型
|
# 判断匹配内容的类型
|
||||||
if (reply_text.startswith("http://") or reply_text.startswith("https://")) and any(reply_text.endswith(ext) for ext in [".jpg", ".jpeg", ".png", ".gif", ".img"]):
|
if (reply_text.startswith("http://") or reply_text.startswith("https://")) and any(reply_text.endswith(ext) for ext in [".jpg", ".webp", ".jpeg", ".png", ".gif", ".img"]):
|
||||||
# 如果是以 http:// 或 https:// 开头,且".jpg", ".jpeg", ".png", ".gif", ".img"结尾,则认为是图片 URL。
|
# 如果是以 http:// 或 https:// 开头,且".jpg", ".jpeg", ".png", ".gif", ".img"结尾,则认为是图片 URL。
|
||||||
reply = Reply()
|
reply = Reply()
|
||||||
reply.type = ReplyType.IMAGE_URL
|
reply.type = ReplyType.IMAGE_URL
|
||||||
|
|||||||
Reference in New Issue
Block a user