Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make it possible to load image from a buffer #13

Open
inikolaev opened this issue May 3, 2018 · 3 comments
Open

Make it possible to load image from a buffer #13

inikolaev opened this issue May 3, 2018 · 3 comments

Comments

@inikolaev
Copy link

Right now it's only possible to load image from a file. I have a use case where I would like to load image from a buffer, specifically the the response contents returned by requests library, e.g.:

import lycon
import requests

response = requests.get("https://example.com/image.jpeg")
image = lycon.load(response.content)
@l3robot
Copy link

l3robot commented Jul 4, 2018

you could use the io python standard library to "fake" a file stream.

import io
import lycon
image = lycon.load(io.BytesIO(buffer))

@nieksand
Copy link

Using a io.BytesIO() didn't work for me:

    return lycon.load(io.BytesIO(png_dat))

_lycon.PyconError: Assertion Failure: `str` evaluated to false in `string_from_pyobject` (/tmp/pip-install-nv5q896g/lycon/src/lycon/python/interop.cc:322)

A gross work around is to write to a temp file and then read from that:

    (fdesc, fname) = tempfile.mkstemp(prefix='tmp-lycon-hack-')
    os.write(fdesc, png_dat)
    os.close(fdesc)

    dat = lycon.load(fname)
    os.remove(fname)
    return dat

@nurpax
Copy link

nurpax commented Jan 9, 2021

It looks from reading the source that Lycon really only supports passing a file name argument to lycon.load(). This makes it impossible to load images from container formats such as a zipfile using lycon and various other uses. I was excited to learn about a faster library than PIL.Image, but the API is a dealbreaker for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants