Jerrad Pierce


CGI::Imagemap - interpret NCSA imagemaps for CGI programs


  use CGI::Imagemap;
  $map = new CGI::Imagemap;


  eval { $action = $map->action($x,$y) };
  #Check $@ for errors


CGI::Imagemap allows CGI programmers to emulate the NCSA imagemap CGI or place TYPE=IMAGE form fields on their forms.

The imagemap file follows that of the NCSA imagemap program. See "NOTES" for further details.


This appends the contents of the file to the map object.


This appends @map to the map object.

  $map->addmap('point 3,9');

This finds the URI defined by the map for the point at x and y. Returns undef if nothing matches. ie; no point and no default directives

  $action = $map->action($x, $y);

action throws an exception if there is an error. You should catch this with block eval and check $@


NCSA Style Image Map Syntax

Blank lines and comments (start with #) are ignored. Each line in the map consists of a directive such as a shape name followed by the URI to associate with the shape and the points defining the shape. A point is an x,y tuple. Supported directives are

default URI

The URI for a selection not within any defined shape, if there are no point directives defined.

point URI point

Point objects do not themselves have to be clicked, instead if no shape was clicked the point closest to the clicked location matches.

circle URI centerPoint edgePoint

A circle with radius extending from centerPoint to edgePoint.

oval URI centerPoint xAxis, yAxis

An oval (ellipse) centered at centerPoint with the defined axes.

  oval 50,50 30,30

Is the same as

  circle 50,50 20,50
rect URI upperLeftPoint lowerRightPoint

A rectangle from upperleftPoint to lowerRightPoint. eg;

  rectangle 10,10 30,30

Is a rectangle with corners at 10,10 10,30 30,30 30,10

poly URI point1 point2 . . . pointN

A closed polygon defined by edges connecting points in the order listed. eg;

  poly 10,10 10,30 30,30 30,10

Is the same as the rectangle above.

The input coordinates are matched against the targets in the order which they were added to the object eg; read from the map file. This is normal behavior and so if you have overlapping shapes be sure to order them properly. Additionally, if you have complex non-overlapping shapes their order will affect the time to match. Place the simplest or most likely to be selected shapes first in your map file.


Jerrad Pierce <>


Based upon CGI::Imagemap 1.00 by Mike Heins <>.

Who intern gladly reused code from by V. Khera <>.

Point in polygon detection based on code by Mike Lyons <>.

Point in oval detection based on code by Lynn Bry <>.