triangler
triangler copied to clipboard
[Q] How to read pictures from bytes and save them as bytes instead of file io
As the title
I'm not sure this is what you want, you can use the convert method in Triangler class. It takes one parameter whose type can be either str(file path in this case) or ndarray. And it returns the result as ndarray, but not saving as an image.
ok,thx I used some weird methods
def make_low_poly(img_bytes):
img = IMG.open(BytesIO(img_bytes)).convert("RGB")
imgx, imgy = img.size
t = triangler.Triangler(sample_method=triangler.SampleMethod.POISSON_DISK, points=max(imgx, imgy))
img = plt.imsave(bio := BytesIO(), t.convert(img.__array__()))
img = IMG.open(bio).convert("RGB")
img.save(bio := BytesIO(), "JPEG")
return bio.getvalue()