In a similar fashion to Gustavo's recommendation, you have the option to set the image as a background within a div or any other element. By utilizing x and y positions on the background image alongside the width and height of the div, you can establish a framed preview of the cropped image. It is crucial for the server to generate the actual cropped file by employing a suitable image library.
For instance, in your scenario, you can modify the onSelectEnd handler of imgAreaSelect()
like this:
$('#ladybug').imgAreaSelect({
onSelectEnd: function (img, selection) {
var div = $('.imgwrapper2');
// Set background image
div.css('background-image', 'url(' + img.src + ')');
// Define width
div.css('width', selection.x2 - selection.x1);
// Determine height
div.css('height', selection.y2 - selection.y1);
// Offset for x
div.css('background-position-x', -selection.x1);
// Offset for y
div.css('background-position-y', selection.y2);
}
});
It is important to note that the x coordinate value for the background image should be the negative of selection.x1
.