As in Gustavo's answer, you can put the image as the background of the div (or any element), and then use the x and y positions on the background image combined with the width and height of the div to create a preview in the frame of the cropped image. The actual cropped file must be generated on the server using the appropriate image library.
Using your example, you can update the onSelectEnd handler imgAreaSelect()as follows:
$('#ladybug').imgAreaSelect({
onSelectEnd: function (img, selection) {
var div = $('.imgwrapper2');
div.css('background-image', 'url(' + img.src + ')');
div.css('width', selection.x2 - selection.x1);
div.css('height', selection.y2 - selection.y1);
div.css('background-position-x', -selection.x1);
div.css('background-position-y', selection.y2);
}
});
Note that the value for the coordinate of the background image x is a negative value selection.x1.
source
share