[Image-SIG] Re: PIL, popen, and GTK

Fredrik Lundh fredrik at pythonware.com
Thu Jun 24 18:21:47 EDT 2004


Phillip Neumann wrote:
> Im trying to develop my program with PIL.
> Im popen a command, qcamshot, that gives me an ppm image from the
> webcam. The ides is to process it with PIL, and show it with Py-GTK.
> 1) how do i get a pil image from memory? i.e. from
> ppm = popen(' qcamshot','r').read()

popen() returns a file handle, so the following might work:

    ppm = Image.open(popen(...))

if not, wrap the image in a StringIO object:

    import StringIO
    data = popen(...).read()
    ppm = Image.open(StringIO.StringIO(data))

also see the fromstring() and frombuffer() functions in the Image
module docs.

</F>






More information about the Image-SIG mailing list