triangler icon indicating copy to clipboard operation
triangler copied to clipboard

[Q] How to read pictures from bytes and save them as bytes instead of file io

Open djkcyl opened this issue 4 years ago • 2 comments

As the title

djkcyl avatar Oct 28 '21 00:10 djkcyl

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.

tdh8316 avatar Oct 28 '21 02:10 tdh8316

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()

djkcyl avatar Oct 28 '21 02:10 djkcyl