madmax61
asked on
Browser output of HTML tables plus gnuplot image on same page without use of external files
In a browser running a perl CGI-BIN program(Linux) I want to call another program (FORTRAN program running on Linux) to extract data which passes back the data (after a lot of mathematical processing) to the perl program, and the result being 2 HTML tables followed by a single gnuplot plot of curves all on one page of the browser.
I can do just the HTML tables output no worries.
I think I can do the curves on a page on its own without the use of creating files on the Linux server and linking back to it from the HTML. That is generating the plot straight to the browser using:
(sample of code below)
$process=open2(GP,GP,"/usr /bin/gnupl ot");
print GP "set terminal png small color");
print GP "title ...
print GP ....size, border, logscale,xrange,yrange,xla bel,ylabel ,xtics,gri d etc etc
print $query->header('image/png' );
# initiate the plot
print GP "plot '-' using 1:2 title \"1 year\" with linespoints lt 1 pt 1 ps 2, '-' using 1:2 title ...etc
The problem with this code above is I can ONLY plot the gnuplot curve on the browser page because of the' image/png' header telling the browser the following data hitting the browser is an image. That is I cannot put the HTML tables below or above the gnuplot.
Any ideas how I can get both HTML generated tables of the data, PLUS an image generated on the fly by gnuplot?
P.S. The gnuplot module within perl is not installed on this system (I believe), and not sure if they would either. Gnuplot is installed as a standalone appilcation on the unix server though.
Note I am trying to to all this without creating files on the Linux server and then linking to it in the HTML followed by necessary file cleanup, unless you can help me with creating random filenames, and cleaning up afterwards I suppose. This program may be called by many people on a high traffic site.
Cheers,
Max
I can do just the HTML tables output no worries.
I think I can do the curves on a page on its own without the use of creating files on the Linux server and linking back to it from the HTML. That is generating the plot straight to the browser using:
(sample of code below)
$process=open2(GP,GP,"/usr
print GP "set terminal png small color");
print GP "title ...
print GP ....size, border, logscale,xrange,yrange,xla
print $query->header('image/png'
# initiate the plot
print GP "plot '-' using 1:2 title \"1 year\" with linespoints lt 1 pt 1 ps 2, '-' using 1:2 title ...etc
The problem with this code above is I can ONLY plot the gnuplot curve on the browser page because of the' image/png' header telling the browser the following data hitting the browser is an image. That is I cannot put the HTML tables below or above the gnuplot.
Any ideas how I can get both HTML generated tables of the data, PLUS an image generated on the fly by gnuplot?
P.S. The gnuplot module within perl is not installed on this system (I believe), and not sure if they would either. Gnuplot is installed as a standalone appilcation on the unix server though.
Note I am trying to to all this without creating files on the Linux server and then linking to it in the HTML followed by necessary file cleanup, unless you can help me with creating random filenames, and cleaning up afterwards I suppose. This program may be called by many people on a high traffic site.
Cheers,
Max
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
The program in full (which doesn't work) currently is:
#!/usr/bin/perl
use IPC::Open2;
#($returned,$ifdtable)=spl it('::::', `/web/cgi- bin/hydro/ has/ifd_ta ble_simple 23000 123000`);
#print $returned;
print "Content_Type: text/html\n\n";
print "<html>";
print "<head><title>testing 1 2 3<\/title><\/head>";
print "<body>";
print "blah blah blah";
$process = open2(OUT, GP, "/usr/bin/gnuplot");
print GP << "end_commands";
set term png
set title "Test 2"
plot sin(x)
end_commands
close GP;
$| = 1;
#print "Content_Type: image/png\n\n";
@pngdata = <OUT>;
#print @pngdata;
print "<img src=\"data:image/png;base6 4,",@pngda ta,\">";
print "blah blah blah again";
print "<\/body>";
print "<\/html>";
#!/usr/bin/perl
use IPC::Open2;
#($returned,$ifdtable)=spl
#print $returned;
print "Content_Type: text/html\n\n";
print "<html>";
print "<head><title>testing 1 2 3<\/title><\/head>";
print "<body>";
print "blah blah blah";
$process = open2(OUT, GP, "/usr/bin/gnuplot");
print GP << "end_commands";
set term png
set title "Test 2"
plot sin(x)
end_commands
close GP;
$| = 1;
#print "Content_Type: image/png\n\n";
@pngdata = <OUT>;
#print @pngdata;
print "<img src=\"data:image/png;base6
print "blah blah blah again";
print "<\/body>";
print "<\/html>";
ASKER
I tried the sample from the site in a file, and that doesnt display a picture either:
<html>
<head><title>test</title>< /head>
<body>
testing
<IMG
SRC="data:image/gif;base64 ,R0lGODdhM AAwAPAAAAA AAP///ywAA AAAMAAwAAA C8IyPqcvt3 wCcDkiLc7C 0qwyGHhSWp jQu5yqmCYs apyuvUUlvO NmOZtfz
gFzByTB10QgxOR0TqBQejhRNzO fkVJ+5YiUq rXF5Y5lKh/ DeuNcP5yLW GsEbtLiOSp a/TPg7JpJH xyendzWTBf X0cxOnKPjg Bzi4diinWG dkF8kjdfny cQZXZeY
GejmJlZeGl9i2icVqaNVailT6F 5iJ90m6mvu TS4OK05M0v Dk0Q4XUtwv KOzrcd3iq9 uisF81M1OI cR7lEewwcL p7tuNNkM3u Nna3F2JQFo 97Vriy/Xl4 /f1cf5V
WzXyym7PHhhx4dbgYKAAA7"ALT ="Larry">
testing 2
</body>
</html>
<html>
<head><title>test</title><
<body>
testing
<IMG
SRC="data:image/gif;base64
gFzByTB10QgxOR0TqBQejhRNzO
GejmJlZeGl9i2icVqaNVailT6F
WzXyym7PHhhx4dbgYKAAA7"ALT
testing 2
</body>
</html>
ASKER
Some more googling uncovered this statement:
" It seems that IE6 does not support the RFC 2397 'data' scheme. Maybe it will
in IE7.
Firefox and Opera support it. "
I tried the sample and it worked in mozilla, and doesnt work on my IE6. Still didnt get my own program working in mozilla but defeats the purpose if it won't work on IE6 and below. It isn't an acceptable solution to only work in version 7 of IE and above.
Cheers,
Max
" It seems that IE6 does not support the RFC 2397 'data' scheme. Maybe it will
in IE7.
Firefox and Opera support it. "
I tried the sample and it worked in mozilla, and doesnt work on my IE6. Still didnt get my own program working in mozilla but defeats the purpose if it won't work on IE6 and below. It isn't an acceptable solution to only work in version 7 of IE and above.
Cheers,
Max
Could you make one script generate the
Content_Type: text/html\n\n
<html>
<head><title>testing 1 2 3<\/title><\/head>
<body>
blah blah blah
<img src="otherscripttogenerate image?data togenerate image">
and do the
Content_Type: image/png\n\n@pngdata
in the otherscript
Content_Type: text/html\n\n
<html>
<head><title>testing 1 2 3<\/title><\/head>
<body>
blah blah blah
<img src="otherscripttogenerate
and do the
Content_Type: image/png\n\n@pngdata
in the otherscript
What if you put the file handle into binary mode before you print the image?
ASKER
Ozo:
RE: <img src="otherscripttogenerate image?data togenerate image">
Is this valid HTML, can I call a script like that? Also will it too be part of the same or similar RFC that won't support less than I.E. 7?
Mjcoyne:
Are you suggesting this line:
$process = open2(OUT, GP, "/usr/bin/gnuplot");
be given a binary mode for the open ?
How will this help, what are you trying to achieve there?
Sorry I don't understand where you are going with that.
p.s. Apologies for not getting back sooner, I have been on a course this week.
Regards and thanks,
Max
RE: <img src="otherscripttogenerate
Is this valid HTML, can I call a script like that? Also will it too be part of the same or similar RFC that won't support less than I.E. 7?
Mjcoyne:
Are you suggesting this line:
$process = open2(OUT, GP, "/usr/bin/gnuplot");
be given a binary mode for the open ?
How will this help, what are you trying to achieve there?
Sorry I don't understand where you are going with that.
p.s. Apologies for not getting back sooner, I have been on a course this week.
Regards and thanks,
Max
You earlier said "But I get screen garbage (eg text representing the image)". This is usually the result of printing a binary file in ASCII mode. I would put whatever filehandle produced the "screen garbage" into binary mode.
Why do you not want gnuplot to just create a file on the Linux server that you can link to via HTML?
I'm not sure how we got into base64...
Why do you not want gnuplot to just create a file on the Linux server that you can link to via HTML?
I'm not sure how we got into base64...
ASKER
I've decided I will go down the path of creating files on linux, and linking to it, and will need to run a file cleanup routine in cron.
Whilst I think the answers given will work under certain circumstances (eg certain browser levels) I don't feel it is suitable for me, so I will still award the points for the suggestions.
Cheers,
Max
Whilst I think the answers given will work under certain circumstances (eg certain browser levels) I don't feel it is suitable for me, so I will still award the points for the suggestions.
Cheers,
Max
ASKER
Here is a sample of the type of thing I am doing:
I can't get it to work, could you please give me a little more guidance in how to get it working.
#!/usr/bin/perl
use IPC::Open2;
$process = open2(OUT, GP, "/usr/bin/gnuplot");
print GP << "end_commands";
set term png
set title "Test 2"
plot sin(x)
end_commands
close GP;
$| = 1;
print "Content_Type: image/png\n\n";
@pngdata = <OUT>;
print @pngdata;
From your link provided I need it to look similar to:
<IMG
SRC="data:image/gif;base64
AAAC8IyPqcvt3wCcDkiLc7C0qw
ByTB10QgxOR0TqBQejhRNzOfkV
a/TPg7JpJHxyendzWTBfX0cxOn
ZeGl9i2icVqaNVailT6F5iJ90m
F81M1OIcR7lEewwcLp7tuNNkM3
hhx4dbgYKAAA7"
ALT="Larry">
I'm modifying these 3 lines essentially:
print "Content_Type: image/png\n\n";
@pngdata = <OUT>;
print @pngdata;
to look like:
print "<img src=\"data:image/png;base6
But I get screen garbage (eg text representing the image):
IT looks like:
<img src="data:image/png;base64
IHDR € à
Any ideas where I am going wrong?
Cheers,
Max