def send_image(self, chat_id, image):
if isinstance(image, bytes):
f = BytesIO(image)
f.seek(0)
extension = imghdr.what(f)
self.bot.sendPhoto(chat_id, ('image.' + extension, f))
elif isinstance(image, str):
with open(image, 'rb') as f:
self.bot.sendPhoto(chat_id, f)
elif hasattr(image, 'read'):
if hasattr(image, 'name'):
self.bot.sendPhoto(chat_id, image)
else:
self.bot.sendPhoto(chat_id, ('image.png', image))
else:
raise TypeError(
'image needs to be either a filename, bytes or file-like object'
)
评论列表
文章目录