DTML Method or PyScript returning image?
Greetings all; I've got a question about Images for you. Basically, my situation is this: I've got images 1.gif, 2.gif, 3.gif, and 4.gif in a folder. What I want to do is set up an object of some sort called "image.gif", which, when called, would randomly return one of the other graphics in the Folder. I'm guessing I'll have to set the content-type of the image and then just return the data, but it's returning the data that's the problem. Here's basically what I've got in a Python Script right now:
myImage = context[str(context.getImageNum()) + '.gif']
RESPONSE.setHeader('Content-Type', myImage.getContentType()) return myImage
"getImageNum" is another Python Script in the same directory which returns a valid number for the graphic, and that part works fine. The Content-Type is set properly as well, but when I return the image, it actually returns the "<IMG SRC= . . .>" rather than the image data itself. I'm using Zope 2.3.2, if that makes a difference . . . Thanks in advance for help! -CJ WOW: Rapacious | A priest advised Voltaire on his death bed to apocalyptech.com/wow | renounce the devil. Replied Voltaire, "This pez@apocalyptech.com | is no time to make new enemies."
Hi CJ! On Tuesday 09 October 2001 17:27, you wrote:
...
The Content-Type is set properly as well, but when I return the image, it actually returns the "<IMG SRC= . . .>" rather than the image data itself.
The image data lies in myImage.data :-) hth, Danny
On Tue Oct 9 00:00:30 2001, Danny William Adair wrote:
The image data lies in myImage.data
Ah, that did the trick. Thanks. I was expecting it to be a function call, so I was trying "myImage.data()" and "myImage.getData()" and so on. Thanks again! -CJ WOW: Rapacious | A priest advised Voltaire on his death bed to apocalyptech.com/wow | renounce the devil. Replied Voltaire, "This pez@apocalyptech.com | is no time to make new enemies."
On Mon, 8 Oct 2001, CJ Kucera wrote:
Basically, my situation is this: I've got images 1.gif, 2.gif, 3.gif, and 4.gif in a folder. What I want to do is set up an object of some sort called "image.gif", which, when called, would randomly return one of the other graphics in the Folder.
Maybe I'm misunderstanding your requirements, but a quick Python script can return a selection from a group of images. Something like: """ This script returns a random image. """ import random return random.choice(context.objectValues('Image')) I use this appoach to display a random quote at the bottom of my Web page. -Tim -- Tim Wilson | Visit Sibley online: | Check out: Henry Sibley HS | http://www.isd197.org | http://www.zope.com W. St. Paul, MN | | http://slashdot.org wilson@visi.com | <dtml-var pithy_quote> | http://linux.com
On Tue Oct 9 06:48:24 2001, Timothy Wilson wrote:
Maybe I'm misunderstanding your requirements, but a quick Python script can return a selection from a group of images. Something like:
""" This script returns a random image. """ import random return random.choice(context.objectValues('Image'))
Actually, that's not really what I want, because there are more images in the directory than I want to include in the random "rotation" (I suppose I could move 'em off to another directory, though). In any case, that bit's working the way I want it, and now the other bit is, too. But thanks! -CJ WOW: Rapacious | A priest advised Voltaire on his death bed to apocalyptech.com/wow | renounce the devil. Replied Voltaire, "This pez@apocalyptech.com | is no time to make new enemies."
CJ Kucera wrote:
Actually, that's not really what I want, because there are more images in the directory than I want to include in the random "rotation"
Have a look at http://www.zope.org/Members/phd/Random . RandomLine_v works great for that issue. Cheers, Andreas -- Andreas Wandel / Institut fuer Mathematik Systemtechnik / Universitaet Potsdam wandel@math.uni-potsdam.de / http://www.math.uni-potsdam.de ech`echo xiun|tr nu oc|sed 'sx\([sx]\)\([xoi]\)xo un\2\1 is xg'`ol
participants (4)
-
Andreas Wandel -
CJ Kucera -
Danny William Adair -
Timothy Wilson