Col*_*ave 6 python api image telegram-bot
我想根据要求发送图像(通过 URL 或路径)。我在这里使用源代码。 该代码已经有一个发送图像的示例(通过 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())
Run Code Online (Sandbox Code Playgroud)
一些 API 信息可以在这里找到。
谢谢你的耐心。
小智 5
从 URL 发送照片:
bot.send_photo(chat_id=chat_id, photo='https://telegram.org/img/t_logo.png')
Run Code Online (Sandbox Code Playgroud)
要从本地云端硬盘发送照片:
bot.send_photo(chat_id=chat_id, photo=open('tests/test.png', 'rb'))
Run Code Online (Sandbox Code Playgroud)
这是参考文档。
| 归档时间: |
|
| 查看次数: |
11519 次 |
| 最近记录: |