# Find What Image Map Area A Pixel Is In

## Recommended Posts

Hi,I was wondering if there is a way to find what area, of an image map, a given pixel is in?ThanksDuncan

##### Share on other sites

If you use <input type="image"> you can get the X and Y position of the clicked pixel on the server-side, if that's any help.

##### Share on other sites

Thanks for the reply but Im afraid that doesnt help ...

##### Share on other sites

Can you give a clearer idea of what you want to do?

##### Share on other sites

I have a map of the world and each country is an area on an image map.The user will select a start location and an end location and the script will cycle through each pixel in a direct line from the start to the end and i want to find out what country the pixel is in or if it is over sea.

##### Share on other sites

You'd have to define which pixels are what country somewhere or another.

##### Share on other sites

You mean every pixel, there is no way to find out what pixels are within a polygon area??

##### Share on other sites

Correct, there's not a built-in way to do that. You would need to have a Javascript array or something similar where you define the regions and what pixels they cover that you can use to cross-reference a pixel with a region.

##### Share on other sites

that would take a very long time as the polygon is very large.ahh well i will have to think of some alternative method.Thanks very much anyway

##### Share on other sites

From the basic details it sounds like Flash might be an option.

##### Share on other sites

You could devise an algorithm and mathematical formula to find out which pixels are in the area by the coordinates. I'm not going to tell you how to do that, though. I'd need to do some research myself, it's not something simple because it requires geometry.

##### Share on other sites

That would involve dividing the region into specific polygons like triangles and squares, and then computing the area of the parts. The formulas for computing the area of a triangle or square are well-known.

##### Share on other sites

hmmm, sounds complicated.May look into finding the pixels that lie along the lines of the edge of the polygon and finding if the path crosses one of these lines.Thanks for the posts.