convert to stdout, and piping it to Python/PIL

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
ikonamagick

convert to stdout, and piping it to Python/PIL

Post 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.
ikonamagick

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

Post 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)
Post Reply