CLImage icon indicating copy to clipboard operation
CLImage copied to clipboard

[REQUEST] Load image from bytes

Open DuckyMomo20012 opened this issue 3 years ago • 1 comments

I think it would be better if the library exposes a function to load images directly from bytes instead of reading from a file. For example, downloading images from API, so I don't have to write image data to file locally.

DuckyMomo20012 avatar Jul 14 '22 01:07 DuckyMomo20012

You can use BytesIO from the io standard library to create a file in memory

import requests
from io import BytesIO
import climage


def main():
    r = requests.get("image_url")
    with BytesIO(r.content) as img:
        print(climage.convert(img))


if __name__ == "__main__":
    main()

Tyarel8 avatar Jul 21 '22 09:07 Tyarel8

That's a great approach, thank you ❤️ P.S. Sorry for the late reply 😅

DuckyMomo20012 avatar Aug 14 '22 10:08 DuckyMomo20012