Image Streaming

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Steffen Brodowski

    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 "CreateBarc ode" 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(S ourceString,Lin ewidth,WriteTex t):
    blablabla
    ...
    NewImage = Image.new("L",N ewSize,Backcolo r)
    ImgDraw = ImageDraw.Draw( NewImage)
    ....

    #How to put the image into an stream?

    best regards

    Steffen Brodowksi
    Germany
  • piter

    #2
    Re: Image Streaming


    Uzytkownik "Steffen Brodowski" <st.brodowski@e ucrea.com> napisal w
    wiadomosci news:381a2b17.0 307072326.211c2 1b5@posting.goo gle.com...[color=blue]
    > 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 "CreateBarc ode" 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(S ourceString,Lin ewidth,WriteTex t):
    > blablabla
    > ...
    > NewImage = Image.new("L",N ewSize,Backcolo r)
    > ImgDraw = ImageDraw.Draw( NewImage)
    > ....
    >
    > #How to put the image into an stream?[/color]

    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[color=blue]
    >
    > best regards
    >
    > Steffen Brodowksi
    > Germany[/color]


    Comment

    • Ian Bicking

      #3
      Re: Image Streaming

      On Tue, 2003-07-08 at 02:26, Steffen Brodowski wrote:[color=blue]
      > 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 "CreateBarc ode" 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(S ourceString,Lin ewidth,WriteTex t):
      > blablabla
      > ...
      > NewImage = Image.new("L",N ewSize,Backcolo r)
      > ImgDraw = ImageDraw.Draw( NewImage)
      > ....
      >
      > #How to put the image into an stream?[/color]

      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



      Comment

      • JanC

        #4
        Re: Image Streaming

        Fernando Perez <fperez528@yaho o.com> schreef:
        [color=blue]
        > or even gif (the patents expired recently).[/color]

        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

        Comment

        • Fredrik Lundh

          #5
          Re: Image Streaming

          Fernando Perez wrote:
          [color=blue]
          > For barcodes, use png, tiff or even gif (the patents expired recently).[/color]

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

          </F>




          Comment

          • Steffen Brodowski

            #6
            Re: Image Streaming

            Hi Ian,

            [color=blue][color=green]
            > >
            > > import Image, ImageDraw
            > > def CreateBarcode(S ourceString,Lin ewidth,WriteTex t):
            > > blablabla
            > > ...
            > > NewImage = Image.new("L",N ewSize,Backcolo r)
            > > ImgDraw = ImageDraw.Draw( NewImage)
            > > ....
            > >
            > > #How to put the image into an stream?[/color]
            >
            > 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')[/color]


            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=Barco de,
            functionname=Cr eateBarcode.

            I'm using the following line in Zope DTML
            <dtml-var "barcode(Source String='1234567 89',Linewidth=1 ,WriteText=0)">
            or
            <img src="<dtml-var "barcode128(Sou rceString='1234 56789',Linewidt h=1,WriteText=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

            Comment

            • Ian Bicking

              #7
              Re: Image Streaming

              On Wed, 2003-07-09 at 09:22, Steffen Brodowski wrote:[color=blue][color=green]
              > > 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')[/color]
              >
              >
              > 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=Barco de,
              > functionname=Cr eateBarcode.
              >
              > I'm using the following line in Zope DTML
              > <dtml-var "barcode(Source String='1234567 89',Linewidth=1 ,WriteText=0)">[/color]

              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(outp ut, 'GIF')
              return output.getvalue ()




              Comment

              • Fernando Perez

                #8
                Re: Image Streaming

                JanC wrote:
                [color=blue]
                > Fernando Perez <fperez528@yaho o.com> schreef:
                >[color=green]
                >> or even gif (the patents expired recently).[/color]
                >
                > Only in the US, not in (some countries in) Europe & Japan.[/color]

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

                Best,

                f.

                Comment

                • JanC

                  #9
                  Re: Image Streaming

                  Fernando Perez <fperez528@yaho o.com> schreef:
                  [color=blue][color=green][color=darkred]
                  >>> or even gif (the patents expired recently).[/color]
                  >>
                  >> Only in the US, not in (some countries in) Europe & Japan.[/color]
                  >
                  > Ah, you're right. But I think they also expire soon, don't they?[/color]

                  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

                  Comment

                  • Steffen Brodowski

                    #10
                    Re: Image Streaming

                    Hi Ian,
                    [color=blue]
                    > from cStringIO import StringIO
                    > def CreateBarcode(. ..):
                    > # create image object
                    > output = StringIO()
                    > image.save(outp ut, 'GIF')
                    > return output.getvalue ()[/color]

                    Yes, it works! Thank you!!

                    Steffen Brodowski

                    Comment

                    Working...