Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Image Streaming

Reply
Thread Tools

Image Streaming

 
 
Steffen Brodowski
Guest
Posts: n/a
 
      07-08-2003
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?

best regards

Steffen Brodowksi
Germany
 
Reply With Quote
 
 
 
 
piter
Guest
Posts: n/a
 
      07-08-2003

Uzytkownik "Steffen Brodowski" <(E-Mail Removed)> napisal w
wiadomosci news:(E-Mail Removed) om...
> 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?


Image.save
save(outfile, options)
save(outfile, format, options)
Saves the image under the given filename. If format is omitted, the format
is determined from the filename extension, if possible. This method returns
None.
Keyword options can be used to provide additional instructions to the
writer. If a writer doesn't recognise an option, it is silently ignored. The
available options are described later in this handbook.
You can use a file object instead of a filename. In this case, you must
always specify the format. The file object must implement the seek, tell,
and write methods, and be opened in binary mode.

hth
Piter
>
> best regards
>
> Steffen Brodowksi
> Germany



 
Reply With Quote
 
 
 
 
Ian Bicking
Guest
Posts: n/a
 
      07-08-2003
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')

Ian



 
Reply With Quote
 
JanC
Guest
Posts: n/a
 
      07-09-2003
Fernando Perez <(E-Mail Removed)> schreef:

> or even gif (the patents expired recently).


Only in the US, not in (some countries in) Europe & Japan.

--
JanC

"Be strict when sending and tolerant when receiving."
RFC 1958 - Architectural Principles of the Internet - section 3.9
 
Reply With Quote
 
Fredrik Lundh
Guest
Posts: n/a
 
      07-09-2003
Fernando Perez wrote:

> For barcodes, use png, tiff or even gif (the patents expired recently).


note that PIL's GIF generator uses run-length encoding, so the
Unisys LZW patents won't matter here.

</F>




 
Reply With Quote
 
Steffen Brodowski
Guest
Posts: n/a
 
      07-09-2003
Hi Ian,


> >
> > 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')



I think its more difficult.

The function CreateBarcode has to return the image directly.
Additional you have to know, that I have to implement it into Zope. So
I use the script as an "external method". Modulname=Barcode,
functionname=CreateBarcode.

I'm using the following line in Zope DTML
<dtml-var "barcode(SourceString='123456789',Linewidth=1,Writ eText=0)">
or
<img src="<dtml-var "barcode128(SourceString='123456789',Linewidth=1,W riteText=0)">">

to generate the barcode and for showing it on a html-site.

But is doesn't run.

Do you have any ideas?

Greetings

Steffen Brodowski
 
Reply With Quote
 
Ian Bicking
Guest
Posts: n/a
 
      07-09-2003
On Wed, 2003-07-09 at 09:22, Steffen Brodowski wrote:
> > 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')

>
>
> I think its more difficult.
>
> The function CreateBarcode has to return the image directly.
> Additional you have to know, that I have to implement it into Zope. So
> I use the script as an "external method". Modulname=Barcode,
> functionname=CreateBarcode.
>
> I'm using the following line in Zope DTML
> <dtml-var "barcode(SourceString='123456789',Linewidth=1,Writ eText=0)">


So then you don't want to stream it. You might do something like:

from cStringIO import StringIO
def CreateBarcode(...):
# create image object
output = StringIO()
image.save(output, 'GIF')
return output.getvalue()




 
Reply With Quote
 
Fernando Perez
Guest
Posts: n/a
 
      07-09-2003
JanC wrote:

> Fernando Perez <(E-Mail Removed)> schreef:
>
>> or even gif (the patents expired recently).

>
> Only in the US, not in (some countries in) Europe & Japan.


Ah, you're right. But I think they also expire soon, don't they? Well, anyway,
png is better

Best,

f.
 
Reply With Quote
 
JanC
Guest
Posts: n/a
 
      07-10-2003
Fernando Perez <(E-Mail Removed)> schreef:

>>> or even gif (the patents expired recently).

>>
>> Only in the US, not in (some countries in) Europe & Japan.

>
> Ah, you're right. But I think they also expire soon, don't they?


Somewhere next year IIRC (at least in most countries).

--
JanC

"Be strict when sending and tolerant when receiving."
RFC 1958 - Architectural Principles of the Internet - section 3.9
 
Reply With Quote
 
Steffen Brodowski
Guest
Posts: n/a
 
      07-11-2003
Hi Ian,

> from cStringIO import StringIO
> def CreateBarcode(...):
> # create image object
> output = StringIO()
> image.save(output, 'GIF')
> return output.getvalue()


Yes, it works! Thank you!!

Steffen Brodowski
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
wx.Image: Couldn't add an image to the image list. Laszlo Zsolt Nagy Python 1 01-26-2005 09:55 PM
Displaying Image after Streaming Stephen ASP .Net 0 11-29-2004 04:13 PM
Streaming Dynamic Image Tscheihpih Java 1 02-18-2004 03:00 PM
Streaming Image data to an image viewer Jerry J ASP .Net 0 07-18-2003 01:33 PM



Advertisments