优化截图,但是会残留大量的文件
This commit is contained in:
@@ -154,7 +154,8 @@ class DifyPlugin(MessagePluginInterface):
|
|||||||
# 如果是普通文本,则在长度大于100字时,转为图片发送
|
# 如果是普通文本,则在长度大于100字时,转为图片发送
|
||||||
if len(response) > 400:
|
if len(response) > 400:
|
||||||
# 转图片
|
# 转图片
|
||||||
respath = await convert_md_str_to_image(response, "dify_output.jpg")
|
output_image = f"dify_output_{int(time.time())}.png"
|
||||||
|
respath = await convert_md_str_to_image(response, output_image)
|
||||||
await bot.send_image_message((roomid if roomid else sender), Path(respath))
|
await bot.send_image_message((roomid if roomid else sender), Path(respath))
|
||||||
else:
|
else:
|
||||||
# 如果是普通文本,使用发送文本方法
|
# 如果是普通文本,使用发送文本方法
|
||||||
@@ -217,7 +218,8 @@ class DifyPlugin(MessagePluginInterface):
|
|||||||
# 如果是普通文本,则在长度大于100字时,转为图片发送
|
# 如果是普通文本,则在长度大于100字时,转为图片发送
|
||||||
if len(response) > 400:
|
if len(response) > 400:
|
||||||
# 转图片
|
# 转图片
|
||||||
respath = await convert_md_str_to_image(response, "dify_output.jpg")
|
output_image = f"dify_output_{int(time.time())}.png"
|
||||||
|
respath = await convert_md_str_to_image(response, output_image)
|
||||||
await bot.send_image_message((roomid if roomid else sender), Path(respath))
|
await bot.send_image_message((roomid if roomid else sender), Path(respath))
|
||||||
else:
|
else:
|
||||||
# 如果是普通文本,使用发送文本方法
|
# 如果是普通文本,使用发送文本方法
|
||||||
|
|||||||
@@ -211,11 +211,16 @@ async def html_to_image(html_file, output_image):
|
|||||||
browser = await p.chromium.launch(executable_path=browser_path)
|
browser = await p.chromium.launch(executable_path=browser_path)
|
||||||
|
|
||||||
# 业务逻辑不变
|
# 业务逻辑不变
|
||||||
|
try:
|
||||||
page = await browser.new_page()
|
page = await browser.new_page()
|
||||||
await page.goto(f'file://{os.path.abspath(html_file)}')
|
await page.goto(f'file://{os.path.abspath(html_file)}')
|
||||||
await page.set_viewport_size({"width": 750, "height": 800})
|
await page.set_viewport_size({"width": 750, "height": 800})
|
||||||
await page.wait_for_timeout(500)
|
await page.wait_for_timeout(500)
|
||||||
await page.screenshot(path=output_image, full_page=True)
|
await page.screenshot(path=output_image, full_page=True)
|
||||||
|
except Exception as e:
|
||||||
|
print(f"截图失败: {e}")
|
||||||
|
finally:
|
||||||
|
await page.close()
|
||||||
await browser.close()
|
await browser.close()
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
Reference in New Issue
Block a user