I have been able to get the selection from the red box with this code:
var selection = window.getSelection().getRangeAt(0);
Which returns a startOffset and a endOffset corresponding to the characters from 0-14 (in this picture) 
But how do you get the same kind of area-selection of a image? The desired output should be like the example below
