#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Posts
    1
    Rep Power
    0

    Question Display image from python script


    Hi
    i have a script called image.py , that chooses a random jpeg file from a folder.
    i wanna be able to use this script as an image file in my CSS
    E.G

    body(
    background : #fff url(/myimages/image.py) no-repeat 100% 100%;\
    )

    this is what i wanna do if the is a better way
    i would appreciate yo help
    Thanks
  2. #2
  3. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    Assuming you have a Python CGI script, all you should have to do is print your CSS in the appropriate place, i.e. Something like this.

    Code:
    #!/usr/bin/env python
    
    import randomimage, othermodules...
    
    print '<head>'
    print '<title>Sample</title>'
    print '<style type="text/css">'
    print 'body {background-image: %s};' % randomimage.URL()
    ...
    rest of CSS.
    ...
    print '</style>'
    print '</head>'
    ...
    Rest of script.
    ...
    This does assume that your random image script is called randomimage that and has a function called URL() that returns the URL to the image, but this is the basic idea .

    Mark.
    programming language development: www.netytan.com Hula

  4. #3
  5. Mini me.
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Location
    Cambridge, UK
    Posts
    783
    Rep Power
    14
    Kusta,
    Can't see how that would work - (someone correct me if I'm wrong please) you would need your web server (apache?) to intercept that url and know to exceute the code and substitute the output. That sounds more like a template system to me.

    How about something like:
    www.mywebsite/cgi-bin/preppage.py?page=welcome
    where preppage.py writes the css and then redirects to welcome.html

    Or if mod-python is available you could use it and have some inline python code for each page to drop in the image file into the css before the page is written.

    Or write the whole file from python as per Mark's suggestion.

    grimey
    Last edited by Grim Archon; November 3rd, 2004 at 05:57 PM.

IMN logo majestic logo threadwatch logo seochat tools logo