CodeCharge Studio
search Register Login  

Web Reporting

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> Perl

 GD::Graph - outputs as a string of characters

Print topic Send  topic

Author Message
Jan
Posted: 03/08/2005, 2:49 PM

I am currently doing my final year project at University using perl cgi.

I have used a cgi script to output data onto the web browser, but have also included code to generate a graph using gd:graph. The problem is that on submit of my form the graph appears as a string of wierd characters onto the browser window. The user input appears as text onto the browser window as specified. If I run the graph as a separate script then it outputs fine.
Ozum

Posts: 57
Posted: 03/08/2005, 2:58 PM

If I get right your problem, you can't see both text and image at the same time with one script. They have different file headers.

You can use <img src="your_image_script.cgi"> to render and send your image below the message.
View profile  Send private message
Jan
Posted: 03/11/2005, 6:03 AM

Hi Ozzum

Thanx for your reply. I am still a bit confused what you mean?
I have put all the code on one cgi script including the graph code. The idea is that on submit of the form - if there are no errors with the form, then the users data will be output in text format together with a graph.

Thsi code has been put in a loop. I can get the text output, with the graph output - except that the graph appears as a string of characters/lines. I dont understand why the graph appears as lines?

Thanks

J
Ozum

Posts: 57
Posted: 03/11/2005, 12:51 PM

Hi,

I try to explain,

According to HTTP standards Internet Browsers or any other client expect a file header. These requests are usually handled via Perl CGI module or GD::Graph

WEB BROWSER -----request(get)-------> WEB SERVER
WEB BROWSER <-------response--------------|

Below are two imaginary get requests for a jpg file and an html file

For jpg file: GET /car.jpg ....
For html file: GET /description.html .....

Web server responses for these requests like these.
...
Content-Length: 141
Content-Type: text/html

Or

...
Content-Length: 4500
Content-Type: image/jpeg

So your browser expect to see a html file (text based) stream in the first one, and a jpeg file stream (binary) in the second one.

In your case you print a HTML file header to write your message and browser capture this text and prints it to screen, but after that your image stream continue to flow as a binary data to the browser. Since browser assumes it is a text stream it tries to print them as its text, and you see strange characters. These strange characters are the same when you look at your jpeg file via a hex editor.

You can combine these two in a script checking it via parameters. Example:
Assume file is named as "combine.cgi"

  
use CGI qw(:all);  
use GD::Graph;  
  
if ( param('give') eq 'message' )  
{  
  print header;  
  print "Hello this is image: <br> <img src='combine.cgi?give=photo'>";  
}  
elsif ( param('give') eq 'photo' )  
{  
  # Here print a jpeg file header. (I don't remember exactly)  
  # And here print your image file with GD  
}  


When you call this file as combine.cgi?give=message this does what you want.

Regards Ozum
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

PHP Reports

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright 2003-2004 by UltraApps.com  and YesSoftware, Inc.