gpt4 book ai didi

Python Telegram 机器人 - 发送图像

转载 作者:太空宇宙 更新时间:2023-11-03 17:27:44 24 4
gpt4 key购买 nike

我想根据请求发送图像(通过 URL 或路径)。我使用来源code here.该代码已经有一个发送图像的示例(通过 URL 或路径),但我不明白,因为我是 Python 新手。

这是示例代码片段:

elif text == '/image':        #request
img = Image.new('RGB', (512, 512))
base = random.randint(0, 16777216)
pixels = [base+i*j for i in range(512) for j in range(512)] # generate sample image
img.putdata(pixels)
output = StringIO.StringIO()
img.save(output, 'JPEG')
reply(img=output.getvalue())

一些API信息可以是found here.

感谢您的耐心等待。

最佳答案

要从 URL 发送照片:

bot.send_photo(chat_id=chat_id, photo='https://telegram.org/img/t_logo.png')

要从本地云端硬盘发送照片:

bot.send_photo(chat_id=chat_id, photo=open('tests/test.png', 'rb'))

Here是引用文档。

关于Python Telegram 机器人 - 发送图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32326851/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com