对于我的电报机器人(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)
Run Code Online (Sandbox Code Playgroud)
因为是我自己生成的,所以不能使用 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 = 0
for im in images:
new_im.paste(im, (x_offset, 0))
x_offset += im.size[0]
return new_im # returns a PIL.Image.Image
Run Code Online (Sandbox Code Playgroud)
提前致谢:) 圣诞快乐
python type-conversion python-imaging-library python-3.x python-telegram-bot
我正在尝试从一个二维对象数组打印一个表格,其中包含一个属性“文本”。它只打印表格行,遍历字段不起作用。
我的 component.html 看起来像这样:
<section *ngIf="object">
<table>
<tr *ngFor="let row of array; let even = even; let odd = odd"
[ngClass]="{ odd: odd, even: even }">
<td class="field" *ngFor="let field of array[row]">
{{field.text}}
</td>
</tr>
</table>
</section>Run Code Online (Sandbox Code Playgroud)
数组:object[][] 已正确填充,我可以将“文本”属性记录到控制台。问题是:我不知道如何遍历第二维 ( *ngFor="let field of array[row]")