I have different images in svg and png and I want to be able to drag those figures only by their image itself. So I want to be able to "ignore" or disable areas from draggable that are invisible.
I've tried different approaches like drawing the images onto a <canvas> element and tried to get the pixels that are greater than zero but I haven't been successfully. What else could I do?
window.onload = function() {
var c = document.getElementById("canvas");
var ctx = c.getContext("2d");
var img1 = new Image();
img1.src = "favicon.svg";
ctx.drawImage(img1, 0, 0, 200, 150);
$(c).draggable();
var currentCanvas = ctx.getImageData(0, 0, 200, 150);
var pix = currentCanvas.data;
if (pix[3] > 0) { // 0 is transparent, 1 up to 255 is visible
$(pix).draggable();
}
}