Pixel Location in Images

From Caves of Narshe Development Wiki
Revision as of 17:15, 7 August 2011 by R51 (talk | contribs)
Jump to navigation Jump to search

Sometimes, most recently for the non-script version of the FF5 map, we need to figure out where the top-left pixel of a particular location in an image falls. This HTML file includes javascript so that a person need only point the file to the right image and put in the right image size, and then the file can be opened in a browser and then the image can be clicked to get x/y coordinates.

<html>
<head>
<script language="JavaScript">
function point_it(event){
	pos_x = event.offsetX?(event.offsetX):event.pageX-document.getElementById("pointer_div").offsetLeft;
	pos_y = event.offsetY?(event.offsetY):event.pageY-document.getElementById("pointer_div").offsetTop;
	document.getElementById("cross").style.left = (pos_x-1) ;
	document.getElementById("cross").style.top = (pos_y-15) ;
	document.getElementById("cross").style.visibility = "visible" ;
	document.pointform.form_x.value = pos_x;
	document.pointform.form_y.value = pos_y;
}
</script>
</head>
<body>
<form name="pointform" method="post">
< div id="pointer_div" onclick="point_it(event)" style = "background-image:url('third.png');width:512px;height:450px;">
<img src="point.gif" id="cross" style="position:relative;visibility:hidden;z-index:2;"></ div>
You pointed on y = <input type="text" name="form_y" size="4" /> - x = <input type="text" name="form_x" size="4" /> 
</form> 
</body>
</html>