waynegm/imgViewer

pos.x real width. Not 1

Closed this issue · 4 comments

How can I change coordinates on this
$("#click_position").html(e.pageX + " " + e.pageY + " " + pos.x + " " + pos.y);
to pos.x real width of image?

The cursorToImg function returns relative image coordinates. Just multiply the x coordinate by the image width and the y coordinate by the image height to get the corresponding image pixel.

var relpos = self.cursorToImg( e.pageX, e.pageY );
var imgposX = pos.x * $("#image").prop('naturalWidth');
var imgposY = pos.y * $("#image").prop('naturalHeight');

waynegm, thank you!
But i have result like that "Click Position x757.8571428571423 y481.5848214285711"
How can I get result like thaht "Click Position x757 y481"

Use the javascript Math.round method

var imgposX = Math.round(pos.x * $("#image").prop('naturalWidth'));
var imgposY = Math.round(pos.y * $("#image").prop('naturalHeight'));

As I haven't heard back I presume your now OK so I'll close this.