Page 1 of 1

convert to stdout, and piping it to Python/PIL

Posted: 2010-02-16T04:21:11-07:00
by ikonamagick
Hello :-)
I am using imagamagick to convert a file and write it to standard out

Code: Select all

convert inimg.bmp jpeg:-
Then I would like to pipe it to a Python (2.6) program that usues the popular Python Imaging Library (PIL), like:

Code: Select all

convert inimg.bmp jpeg:- | python program.py
the program that fails is :

Code: Select all

import sys
import Image

imConvertOut= sys.stdin # IM convert output

pilImage = Image.open(imConvertOut)

pilImage.show() #just displays the image
I would like not to use any IM python binding. This may be a topic for a Python forum but it may be more likely that IM users may have faced this problem before.
Thanks in advance for your help.
cheers, :-)
p.

Re: convert to stdout, and piping it to Python/PIL

Posted: 2010-02-16T06:19:51-07:00
by ikonamagick
a possible answer to my own post :-)
I tried the following and it works:

Code: Select all

from StringIO import StringIO

completeStdin = sys.stdin.read()
imConvertOut = StringIO(completeStdin)