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

Message ListMessage List     Post MessagePost Message

  Trying to use inline image of a clickable chart
Posted by Mike Meyers on Sep-25-2008 03:57
I have a cgi running on set of hosts behind a VIP. For this question we can use the example code from ChartDirector/perldemo_cgi/clickline.pl.

The demo script (as well as the modified one I use) writes a local file
    #Create the image and save it in a temporary location
    my $chart1URL = $c->makeTmpFile("/tmp/tmpcharts");

and later tries to access it with
    <img src="myimage.pl?img=/tmp/tmpcharts/$chart1URL" border="0" usemap="#map1">

The problem is that with multiple hosts behind a VIP, the file can be written to host-1 and the rendering of the image can happen on host-2. Of course host-2 doesn't have the image so the image does not display.

What I would like to do is use an inline image.... something along the lines of
    <img="data:image/gif;base64,
        R0lGODlhEAAOALMAAOazToeHh0tLS/7LZv/0jvb29t/f3//Ub//ge8WSLf/rhf/3kdbW1
        mxsbP//mf///yH5BAAAAAAALAAAAAAQAA4AAARe8L1Ekyky67QZ1hLnjM
        5UUde0ECwLJoExKcppV0aCcGCmTIHEIUEqjgaORCMxIC6e0CcguWw6aFjsVMk
        kIr7g77ZKPJjPZqIyd7sJAgVGoEGv2xsBxqNgYPj/gAwXEQA7"
        alt="Embedded Image" border="0" usemap="#map1">

(Excuse the line returns above. Inserted to make the question readable)

The above works, but I can't seem to replace the inline image with something like $c-makeChart2($perlchartdir::GIF);

[Reference: http://www.websiteoptimization.com/speed/tweak/inline-images/ ]

Any thoughts on how I can make this work?

Thanks in advance,
Mike

  Re: Trying to use inline image of a clickable chart
Posted by Peter Kwan on Sep-25-2008 04:26
Hi Mike,

Actually, we have studied the problem of delivering an image to the browser extensively. The only methods that can work reliably in all browsers are by using a temporary file, or by directly streaming (like in the "simplebar.pl"). The "inline image" method does not work in all released versions of IE (from IE 1 to IE 7), so I think it is not usable in practice.

If you still want to use it, you may try:

use MIME::Base64;
$encoded = encode_base64($c-makeChart2($perlchartdir::GIF));
print "<img='data:image/gif;base64,$encoded' alt='Embedded Image' border='0' usemap='#map1'>";

(Note: I have not tried the above code myself.)

In your case, the common methods are:

(a) Configure your loading balancing switch to have "session affinity", that is, requests from the same client alway get routed back to the same server.

(b) If your web framework support session variables that can work across multiple servers, you may use session variables to store your chart, instead of using a temporary file.

(c) Instead of using the hard disk, you may store your file in a temporary record in your database. I assume all your servers see the same database.

(d) Structure your code so that it creates the chart two times. The first time is for delivering the image map only. The second time is for streaming the chart to the browser.

Hope this can help.

Regards
Peter Kwan

  Re: Trying to use inline image of a clickable chart
Posted by Donavon on Jun-06-2015 01:04
Do you have an example of:

d) Structure your code so that it creates the chart two times. The first time is for delivering the image map only. The second time is for streaming the chart to the browser.

How would an image & image map be delivered via base64 without using a intermediate file?

Thank You,
~Donavon

  Re: Trying to use inline image of a clickable chart
Posted by Peter Kwan on Jun-06-2015 06:25
Attachments:
Hi Donavon,

I have attached an example for a script that creates the chart two times, one time for
delivering the image map, and the other time for the image itself.

According to the HTTP standard, the HTML stream and the image stream must be two
separate HTTP connections. When you load a web page, the images are normally loaded
using separate URLs with separate HTTP connections. According to HTML standard, the
image map (the area tags and map tags) is HTML, while the image is binary content, so
they are normally delivered in two separate HTTP connections.

Many web frameworks (such as PHP, ASP, ASP.NET, JSP, etc) allows a script to delivery
the image map, and to save the image in memory to be delivered later in a separate HTTP
connection. However, CGI itself does not have this feature, so in the Perl CGI sample
code, we save the chart in the disk as a temporary file instead. If you are not using pure
CGI but other web framework, it is likely that the image can be saved in memory instead
of as a file.

Normally, when a browser sees a URL, it will use it to access the server using an HTTP
connection to obtain the content. However, if the URL is written in the certain way
(which involves using base64 encoding), the browser can consider the URL is the content
itself, and will not access the server. In this way, it is possible to use just one HTTP
connection to deliver both the image map and the image, where the image included in the
URL. You can try to use Google to search for how the URL should be written:

http://en.wikipedia.org/wiki/Data_URI_scheme

Hope this can help.

Regards
Peter Kwan
simplebar.pl
simplebar.pl

1.41 Kb

  Re: Trying to use inline image of a clickable chart
Posted by Donavon on Jun-06-2015 07:21
Thank You!!!