CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Intermediate:
Image Maps



Sep 17, 2000, 6:19 PM

Post #1 of 4 (632 views)
Image Maps Can't Post

I have a Question about Perl Imagemaps using

This is my Current code:
<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>

use CGI;
$query = new CGI;
print $query->header;
print $query->start_html("A Clickable Image");

print $query->startform;
print $query->image_button('picture',"gamegifs/compass.gif");
print "<HR>\n";

if ($query->param) {
($x,$y) = ($query->param('picture.x'),$query->param('picture.y'));
print "<P>Selected Position <EM>($x,$y)</EM>\n";
if ($x == 35 && $y == 5)
print "<P><BOLD> HI HI </BOLD>";
print "<P>No!"

print $query->end_html;

My Question is for the "if ($x == 35 && $y == 5)" How can I say look for all the pixels from 35,5 - 45,5 etc. Isntead of making Ifs for every Pixel =P

-Thanks, Kao Atlantis


Sep 17, 2000, 6:44 PM

Post #2 of 4 (632 views)
Re: Image Maps [In reply to] Can't Post

I started creating a module for this a while back, but never finished it.

If you want a simple rectangle (with (y0,y0) and (x1,y1) being opposite corners) then you can use the following geometric property:

If the point (p1,p2) is within the rectangle formed with opposite corners (x0,y0) and (x1,y1), then x0 <= p1 <= x1, and y0 <= p2 <= y1.

That assumes that x0 < x1, and y0 < y1, of course. So if your range is between (10,5) and (23,40), just use:

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>

if (10 <= $x and $x <= 23 and 5 <= $y and $y <= 40) {
# it's good
else {
# don't you wish Perl had chained comparisons like 1 < $x < 10 ?

I'll let the forum know when/if I complete that imagemapping module.

Jeff "japhy" Pinyan -- accomplished author, consultant, hacker, and teacher


Sep 17, 2000, 6:57 PM

Post #3 of 4 (632 views)
Re: Image Maps [In reply to] Can't Post

Wouldn't ...

if ( ($x => 35 && $x <= 45) && $y = 5 ) {

... work for you in this instance?

Alternately, you can build a matrix of all possibilities and then test for the existance of those co-ordinates.

( Dangit, japhy, a fellow wanders off to answer the phone mid-post and ya beat him to the punch. ;)

[This message has been edited by Kanji (edited 09-17-2000).]


Sep 19, 2000, 6:33 PM

Post #4 of 4 (632 views)
Re: Image Maps [In reply to] Can't Post

I have one more question about Image Maps...

After someone clicks the ImgMap, How would I point it to a URL?

-Thanks, Kao Atlantis


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives