473,320 Members | 2,004 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Image Streaming

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
Jul 18 '05 #1
9 7321

Uzytkownik "Steffen Brodowski" <st**********@eucrea.com> napisal w
wiadomosci news:38**************************@posting.google.c 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

Jul 18 '05 #2
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

Jul 18 '05 #3
Fernando Perez <fp*******@yahoo.com> 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
Jul 18 '05 #4
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>


Jul 18 '05 #5
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
Jul 18 '05 #6
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()


Jul 18 '05 #7
JanC wrote:
Fernando Perez <fp*******@yahoo.com> 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.
Jul 18 '05 #8
Fernando Perez <fp*******@yahoo.com> 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
Jul 18 '05 #9
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
Jul 18 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Jason Murry | last post by:
I have a camera system (Axis) which stores JPG via FTP 1-10fps. There is also a motion jpg live stream. I am trying to store these images either in JPG or in video format so they can be...
4
by: malcolm | last post by:
I've seen several posts around the Internet and many of them either don't work or only partially work. All I'm trying to do is record some action asynchronously from an html file, a sort of logging...
0
by: Jerry J | last post by:
I have a third party image viewer that can display various types of images. The image viewer is ActiveX and lives inside of Internet Explorer. To get the image viewer to retrieve an image, java...
4
by: David W. Simmonds | last post by:
Is there a way I can have a button on a ASP.NET form that when clicked will allow the user to save the image to a file on the client side? I know that the user can simply rclick the image and...
1
by: BluDog | last post by:
Hi I have a class that has a System.Drawing.Image as a property, i would like to display this image on my WebForm, however i think i need to get it into a System.Web.UI.WebControls.Image object,...
1
by: Stephen | last post by:
Hi, I am using an Access database (OLE Object) and storing Image as a bytes after streaming. I am able to read it back as a stream and display it on the browser using the following code:...
3
by: Tom John | last post by:
Hi I am using Office Web Components to generate a GIF image, which i want to display in a picture box. However i am having a problem when i attempt to load the image into the picture box....
4
by: Greg | last post by:
I've searched everywhere for a solution Microsoft .NET Framework V 2.0.50727 AutoEventWireup="false" image2.aspx resize an image on the fly but Page_Load is triggered twice: Any suggestion?...
0
by: =?Utf-8?B?RG9jdG9y?= | last post by:
I am making an application that streams video from a web camera onto the client area of a PictureBox on a Windows CLR Form in MS Visual Studio 2005 (using C++). The streaming video works fine, and...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.