Contents Previous Next

7.3 Using StrokeCSIM()

The simplest way of creating a creating a CSIM image is with the StrokeCSIM() method. As mentioned before this method actually returns a (small) HTML page containing both the image-tag as well as the image map specification. Hence it is not possible to use a script that ends with this method in a standard image-tags src property.

There are two ways to create CSIM (or get hold of) the image maps

  1. Use the CSIM image script as the target in a standard anchor reference, for example
    <a href="mycsimscript.html">
    
    This has the drawback that the image page will only contain the image and nothing else.
  2. The other way will allow the image script to be included in an arbitrary HTML page by just including the image script at the wanted place in the HTML page using any of the standard "include" php statement. For example
    <h2> This is an CSIM image </h2>
    
    <?php
    include "mycsimscript.php"
    ?>
    

Note: If there are several CSIM images on the same page it is necessary to use "include_once" in the scripts for the inclusion of "jpgraph.php" and the other jpgraph library files since the files will be included multiple times on the same page and one or more "Already defined error" will be displayed.

The process to replace Stroke() with StrokeCSIM() is strait forward. Replace all existing calls to Stroke() with the equivalent calls to StrokeCSIM().

The only difference is that it is necessary ti supply a minimum of one file name in the StrokeCSIM() method. The first argument must be the name of the actual image script file including the extension. So for example if the image script is called "mycsimscript.php" it is necessary to write
 

 $graph-> StrokeCSIM( 'mycsimscript.php')


However, it is possible to apply a small "trick" here. PHP maintain a special variable called "__FILE__" which is always set to the current file name. This means you could use the following construction:

 $graph-> StrokeCSIM( basename( __FILE__))

This is a better way since the script can now be renamed without having to change any code in the file which otherwise would be needed.

Note: Why does the script name need to be used as the first parameter? The reason is that in the creation of the HTML page which is sent back we need to refer to the script in the image tag. So why is it not possible to use the PHP_SELF reference? The problem with PHP_SELF is that in the case where we include the image-script in an HTML page and use the PHP_SELF we will get the name of the HTML page and not the actual script in which the PHP_SELF is used. We also can not use the __FILE__ trick in the library since in the context __FILE__ is set to "jpgraph.php". Hence, this must be specified by the client as shown above.

The other arguments to StrokeCSIM() are optional. Please note that if several CSIM images are used in the same HTML page it is also necessary to specify the image map name as the second parameter since all image maps must be unique to properly match each image map against each image. Please consult the class reference StrokeCSIM() for more details.


Contents Previous Next