Image Streaming
Bengt Richter
bokr at oz.net
Tue Jul 8 10:56:37 EDT 2003
On 08 Jul 2003 03:23:36 -0500, Ian Bicking <ianb at colorstudy.com> wrote:
>On Tue, 2003-07-08 at 02:26, Steffen Brodowski wrote:
>> Hello everyone,
>>
>> since one week, I'm programming with python. Its a realy interesting
>> tool. I wrote a script for generating barcodes in jpg-format.
>> Everything is ok, but my function "CreateBarcode" should write the jpg
>> data into an outstream. All barcodes will be generate online, without
>> saving the jpgs on harddisk.
>>
>> Can you give me a tip witch objects I need and how to put the jpg into
>> an outgoing stream?
>>
>> import Image, ImageDraw
>> def CreateBarcode(SourceString,Linewidth,WriteText):
>> blablabla
>> ...
>> NewImage = Image.new("L",NewSize,Backcolor)
>> ImgDraw = ImageDraw.Draw(NewImage)
>> ....
>>
>> #How to put the image into an stream?
>
>have that function return the image object. Then, assuming you are
>doing this in CGI (easily adapted if not), do something like (untested):
>
>import sys
>image = CreateBarCode(...)
>print 'Content-type: image/jpeg\n'
>image.save(sys.stdout, 'JPEG')
>
In case it's windows, I suspect that script will need to be run with python -u
or have some programmed way to ensure binary output.
Of course, if it's CGI it's probably a unix platform, in which case that won't be an issue.
Regards,
Bengt Richter
More information about the Python-list
mailing list