CGI script generates an image ...

Armitage

Banned
Feb 23, 2001
8,086
0
0
I have a cgi script - python fwiw. This script generates a jpg (or png) image. Right now it writes it to the disk with a unique file name, and builds the html sent to the client with a regular img tag to that filename. Then I have a cronjob that runs periodically to clean up all the leftover image files.

It seems there has to be a better way. Is it possible to dump the image straight to the client along with the html instead of writing a file on the disk and linking to it?

 

notfred

Lifer
Feb 12, 2001
38,241
4
0
make HTML that links to the cgi script like this:
<img src="whatever.cgi">

Then make the CGI script output the image data.
 

Armitage

Banned
Feb 23, 2001
8,086
0
0
Originally posted by: notfred
make HTML that links to the cgi script like this:
<img src="whatever.cgi">

Then make the CGI script output the image data.

Ok ....
So you need to call a separate cgi for each image? I was hoping to create all of the images in one script - it's visualization some analysis output that takes some time to run - if I have to re-run it for evey image it will be very slow.

Can you do something like dumping the actual image file contents as the src in the img tag?
 

DaveSimmons

Elite Member
Aug 12, 2001
40,730
670
126
No, that isn't how HTML works.

Your cgi code could return an HTML page or frame instead though. After the cgi has the analysis generate the set of images to temp files it returns a page or frame pointing to all of them.

(you'd trigger the CGI using a form post or a redirect instead of an <img> tag)
 

notfred

Lifer
Feb 12, 2001
38,241
4
0
You could actually do that if you were generating SVG files, thoeretically.

It still wouldn't do you any good. Your process isn't going to run any faster if it outputs to one file or several.
 

Armitage

Banned
Feb 23, 2001
8,086
0
0
Originally posted by: notfred
You could actually do that if you were generating SVG files, thoeretically.

It still wouldn't do you any good. Your process isn't going to run any faster if it outputs to one file or several.

Well, it will run much slower if I have to re-run the analysis for every image on the page as I would have to if I put cgi as the src of every img tag.

Sounds like my current kludge may be as god as it gets.
 

notfred

Lifer
Feb 12, 2001
38,241
4
0
Originally posted by: Armitage
Originally posted by: notfred
You could actually do that if you were generating SVG files, thoeretically.

It still wouldn't do you any good. Your process isn't going to run any faster if it outputs to one file or several.

Well, it will run much slower if I have to re-run the analysis for every image on the page as I would have to if I put cgi as the src of every img tag.

Sounds like my current kludge may be as god as it gets.

Why would you be showing the same image several times on the page? I'd think that if you were generating multiple images, they'd each be different, and thus each require thier own processing.
 

Armitage

Banned
Feb 23, 2001
8,086
0
0
Originally posted by: notfred
Originally posted by: Armitage
Originally posted by: notfred
You could actually do that if you were generating SVG files, thoeretically.

It still wouldn't do you any good. Your process isn't going to run any faster if it outputs to one file or several.

Well, it will run much slower if I have to re-run the analysis for every image on the page as I would have to if I put cgi as the src of every img tag.

Sounds like my current kludge may be as god as it gets.

Why would you be showing the same image several times on the page? I'd think that if you were generating multiple images, they'd each be different, and thus each require thier own processing.

It's the data set behind the images that is the issue. The analysis generates a data set when you load the page. Basically it has to parse a relatively large binary file that is being updated continuously. This is the time consuming step that I don't want to repeat several times for one page load. Then I generate several different plots (6 at last count + a google map) from that data set.
 

notfred

Lifer
Feb 12, 2001
38,241
4
0
Don't parse the entire file each time, only parse the new part of the file. Save the parsed data in a separate file.
 

Chebago

Senior member
Apr 10, 2004
575
0
0
marcyes.com
how the browser or whatnot tells it is an image file is by the header. I know is is possible in php to dump the image, but not sure how to do it in python.

For example, if I did it in php, I could send a Header: image/jpeg and then output the content, the browser would see that it is a jpg and then display it. this way and <img src='image.php"> would work just fine. I have php code that you could look at if that would help, just im me...