I've an image which is 700x500 and the site sets the image as 300x300. ie: <img height="300px" weight="300px">
. I've to know if the image was clicked within the boundary layer or outside the boundary of an ellipse. Btw, based on the width and height of the image the x,y coordinates for the click changes.
bounding_box_area = (40, 150, 290, 380)
I have to draw an ellipse in the center.
I've tried the code below bu it is not working
<canvas id="stage" width="400" height="600"></canvas>
var posX = event.offsetX ? (event.offsetX) : event.pageX - img.offsetLeft;
var posY = event.offsetY ? (event.offsetY) : event.pageY - img.offsetTop;
var bodyRect = img.getBoundingClientRect();
var canvas = document.getElementById('stage');
var ctx = canvas.getContext('2d');
ellipse(ctx,40, 150, 290, 380)
function ellipse(context, cx, cy, rx, ry){
context.save(); // save state
context.beginPath();
context.translate(cx-rx, cy-ry);
context.scale(rx, ry);
context.arc(1, 1, 1, 0, 2 * Math.PI, false);
context.restore(); // restore to original state
context.stroke();
}