ASE Home Page Products Download Purchase Support About ASE
ChartDirector General
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  cgi and inline images
Posted by donna on Dec-10-2010 08:43
Here's a snippet of my codes:

# Output the chart
my $return = $c->makeChart("$real_filename");

my $q = CGI->new;
print $q -> header(),
      $q -> start_html( {-title=>"System Configuration Report for $node_name"} ),
      $q -> h2( {-align => 'center'},"System Configuration Report for $node_name" ),
      $q -> h5( {-align => 'center'},'Retrieved on ', scalar localtime ),
      $q -> p,
      $q -> img( {-src=>$www_filename} ),
#      $q -> img( {-src=>$c->makeChart2($perlchartdir::PNG)} );
      $q -> p,
      $q -> end_html();

the above works by producing a real file and showing it on my web page.

the line that's commented out (#) is what i'd really like to do but can't figure out the incantation.  i'm guessing it's possible, yes?

  Re: cgi and inline images
Posted by Peter Kwan on Dec-10-2010 11:55
Hi donna,

In standard HTML/HTTP, it is illegal to include any image in a web page. (Have you ever seen a HTML web page that includes an image?) The HTML web page can only include an <IMG> tag that contain the URL of the image, not the image itself.

Many people are confused about images in HTML. It is because in MS Word, PDF and most other document formats, you can include an image. However, in standard HTML, you cannot include any image. You can only include an <IMG> tag. The image must be delivered in a separate HTTP connection. You may refer to the HTML/HTTP standard for more details. (There are some browser extensions that allow images to be included in HTML, but they do not work for all browsers.)

Most CGI sample code included in ChartDirector for Perl will stream the image to the browser directly without creating a file on the hard disk. The code is like:

<img src="/cgi-bin/createMyChart.pl">

Then in the code "/cgi-bin/createMyChart.pl", you may use ChartDirector to create an image and print it to stdout (remember to use HTTP MIME type "image/png"). You may refer to the CGI version of the "Simple Pie Chart" sample code for an example.

Hope this can help.

Regards
Peter Kwan