Newbie has question that's not exactly Python...

Gary Walker borealis3 at home.com
Wed Apr 4 17:20:10 EDT 2001


Brilliant!!

The code below (without the exception handling) is almost exactly what I
ended up doing, and now it's working as designed (well, at least this part
is)

I shall integrate the exception handling tonight. I was getting tired of
jumping to another screen to read the error log! Absolutely brilliant, I
would never have thought of that...

Both Andrew and Chris are dead on in recognizing what I was trying to ask.
I apologize to everyone for being so difficult to understand; Technical
Email Composing is a skill I shall attempt to hone for the rest of my
life...

As for what exactly I'm doing... well...

I'd like to be able to dynamically generate a web page, complete with
dynamically generated graphics, for a musical instruction website/idea I've
had for some time now...

Basically, the user would enter some data into any of several planned html
forms, submit, and receive a custom web page that shows how to play guitar
chords, mandolin chords, whatever and etc...

One solution (one I think is awkward) would be to maintain an image of every
conceivable chord a person might want to see.

A better one ("better" meaning less hard drive space is needed, and less
overhead involved in image creation), would be to keep a data file on where
to put one's fingers, read that file, and then dynamically generate the
image to explain the chord(s). This is where I'm headed.

I've seen websites where the chords are generated by JavaScript, and that
solution, while interesting (and clever!), doesn't address several issues
that I hope my site will resolve.

I keep saying "site". Right now it's just an idea; I suppose I can say I'm
optimistic!! :)

If you're not a guitar player, you're probably asleep by now, but hey -
someone *did* ask...

Please don't get too bored with the questions, I may have a couple more
coming!! Thanks again for all the help and the excellent solutions!

Gary Walker

Chris Gonnerman wrote in message ...
>Ok, here is a working block of code based on yours:
>
>#!/usr/bin/env python
>#---------------------------------------------------------
>
>import StringIO, cgi, os, sys, string, Image
>
>im = Image.open('backgroundimage.gif')
># here I'll be drawing all over my image...
>
># Now I want to send it to a browser...
>sfp = StringIO.StringIO()
>im.save(sfp,'gif')
>
>print 'Content-Type: image/gif\n'
>
>sys.stdout.write(sfp.getvalue())
>
>#---------------------------------------------------------
>
>Andrew was right on the money regarding the print statement
>and the extra \n it adds.  I generally do it like this,
>though, *depending* on that extra newline.  On my Apache
>server under Python 1.5.2, this works great.  I didn't need
>the \r's either.
>
>Incidentally, here is a suggestion:
>
>#!/usr/bin/env python
>#---------------------------------------------------------
>
>import sys
>
>sys.stderr = sys.stdout
>sys.stdin.close()
>
>try:
>    import StringIO, cgi, os, string, Image
>
>    im = Image.open('backgroundimage.gif')
>    # here I'll be drawing all over my image...
>
>    # Now I want to send it to a browser...
>    sfp = StringIO.StringIO()
>    im.save(sfp,'gif')
>
>    print 'Content-Type: image/gif\n'
>
>    sys.stdout.write(sfp.getvalue())
>
>except:
>    print 'Content-Type: text/plain\n'
>    import traceback
>    traceback.print_exc(file=sys.stdout)
>
>#---------------------------------------------------------






More information about the Python-list mailing list