简体   繁体   English

如何通过php或javascript从图像获取形状的X和Y轴坐标位置?

[英]How to get a shape's X and Y axis coordinate location from a image by php or javascript?

Its an image and I need to know the X and Y axis coordinate location (in px or anything) of the shape. 它是一幅图像,我需要知道形状的X和Y轴坐标位置(以px或其他形式)。 For example-> The distance between the shape and the top of page or image is 20 px and left 15px. 例如->形状与页面或图像顶部之间的距离为20像素,左侧为15像素。 Is it possible by php or javascript? 有可能通过php或javascript吗?

图片在这里

Ok, so i assume you want to do this: 好的,所以我假设您想这样做:

(given an image) (给定图片)

HTML: HTML:

<img id="img" src="image.png">

now, to get the x and y pos: 现在,获取x和y位置:

javascript: javascript:

function getCoordsOfElement(query) {
    var el = document.querySelector(query);
    var offset = el.getBoundingClientRect();

    return {
        x: offset.left,
        y: offset.top
    };
}

// get the x and y offset of the image
var offset = getCoordsOfElement('#img');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM