[+] Return buffer image

This commit is contained in:
Hykilpikonna
2021-12-22 03:55:21 -05:00
parent 700973efda
commit e95e815673
+14 -3
View File
@@ -1,9 +1,12 @@
from __future__ import annotations from __future__ import annotations
import io
import os import os
import sys import sys
import tempfile import tempfile
import time import time
import wave import wave
from PIL import Image
from subprocess import Popen, PIPE from subprocess import Popen, PIPE
from typing import NamedTuple, Callable from typing import NamedTuple, Callable
@@ -93,6 +96,12 @@ def to_wav(file: str, callback: Callable, start_sec: float = 0, stop_sec: float
return callback(tmp_wav) return callback(tmp_wav)
def show_image_buffer(buf):
im = Image.open(buf)
im.show()
buf.close()
if __name__ == '__main__': if __name__ == '__main__':
args = sys.argv[1:] args = sys.argv[1:]
if len(args) < 0: if len(args) < 0:
@@ -133,10 +142,12 @@ if __name__ == '__main__':
color = colors[r.gender] if r.gender in colors else colors['default'] color = colors[r.gender] if r.gender in colors else colors['default']
ax.axvspan(r.start, r.end - 0.01, alpha=.5, color=color) ax.axvspan(r.start, r.end - 0.01, alpha=.5, color=color)
# Export # Savefig to bytes
buf = io.BytesIO()
plt.axis('off') plt.axis('off')
plt.savefig('../image.png', bbox_inches='tight', pad_inches=0, transparent=False) plt.savefig(buf, bbox_inches='tight', pad_inches=0, transparent=False)
buf.seek(0)
return buf
to_wav('../test.mp3', wav_callback) to_wav('../test.mp3', wav_callback)