對于我的電報機器人(python-telegram-bot),我生成了一個 PIL.Image.Image 并且我想將它直接發送給用戶。有效的是從文件中將圖像作為 bufferedReader 發送,但我不想保護圖像。之后我不再需要它,我可能會同時生成很多不同的圖像,所以保存有點混亂。bot.send_photo(chat_id=update.message.chat_id, photo=open(img_dir, 'rb'), caption='test', parse_mode=ParseMode.MARKDOWN)因為是我自己生成的,所以不能使用 URL 或 file_id。我認為可以將圖像轉換為 bufferedReader,但我只設法從中獲取了一個字節對象,這不起作用。圖像生成如下:images = [Image.open(i) for i in dir_list]widths, heights = zip(*(i.size for i in images))total_width = sum(widths)max_height = max(heights)new_im = Image.new('RGBA', (total_width, max_height))x_offset = 0for im in images: new_im.paste(im, (x_offset, 0)) x_offset += im.size[0]return new_im # returns a PIL.Image.Image提前致謝:) 圣誕快樂
添加回答
舉報
0/150
提交
取消