Hi,
I have a script that generates an image like so:

echo '<img src="image_circuit.php?circuit_id='.$id.'">';

And I would like to know how I could dynamically generate an image map for this image...

The problem I encountered is that the image_circuit.php script cannot communicate the areas of the map to the parent script.
image_circuit.php actually sends an image with the appropriate header content-type to the browser (it sends binary information), so I cannot write the image map in HTML.

How could I do that ???

    You need to know all area coordinates.. so you need to create imagemaps manually.. you can not tell PHP to 'look for asphalt' and let it work as an area...

    so create image maps for each circuit.. and name them the same as your circuits...

    <img src="image_circuit.php?circuit_id='.$id.'" usemap=circuitmap$id>

    <map circuitmap1>
    <!-- define areas -->
    </map>
    <map circuitmap2>
    <!-- define areas -->
    </map>

    something like that...

    even better would be, creating include files of them, so you don't have HTML code, not used in your source.

      well the problem is that I have something like 500 circuits, and information can change over time if an admin updates tha database: a circuit is a link between routers over the world.

      So for example, a circuit could be a link between :
      New-York Router on port s0/0 to Miami Router on port s1/0.

      What I want is an image map with links to New-York Router and Miami Router pages on my site.
      But if the admin updates the database (and the Miami Router becomes Chicago Router for example), the links will have to be updated...

      I thought of writing a temporary file on disk in the image script, then reading this file in the script that generates the HTML, to finally destroy this temporary file after it has been included in the HTML page. The problem is if many users refresh pages at the same page: I have to produce pages that have different names each time.

        Than you can create image map area's for each location in your DB... For Example, New York is one location...

        Store each location in your DB containing it's coordinates... Than include the coordinates into an imagemap, as the location is involved

          That could work... only if the parent script (the one calling the image script) could know which router are involved.
          Right now, only the image script knows that.

          I could know this information in the main script, but only if I queried the database many times more than I actually do.

          Duplicating queries is not much of an option, as it will charge the server too much.

          Here is what I thought of:

          Main.php

          $tmpfname = tempnam ("/", "FOO");
          
          // the image script will write in the temporary file like this:
          echo '<img src="image_circuit.php?circuit_id='.$id.'&tmpfname='.$tmpfname.'">';
          
          include($tmpfname);
          unlink($tmpfname);
          

          image_circuit.php

          $handle = fopen($tmpfname, "w");
          // do the db queries, and make the image...
          fwrite($handle, "writing to tempfile");
          fclose($handle);
          

          Only problem: the GET request made for getting the img (and that in fact runs the image script) is run concurrently to the main script, and the main script can finish before the image script is executed: then the temp file will have been destroyed before it has been used.

            2 years later

            wow this post is super old but i'll try to reboot it 🙂

            i would like to ask a favor

            i have this image that i am using as an image map. it has 5 spots that are links.

            want i want to know is if i can make each link (each circle) light up a different color when it is rolled over. i know how to do basic rollovers but not 5 on the same pic. any help would be appreiciated and heres the pic

              Write a Reply...