Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can i show selected image by ImgAreaSelect in a new div

this is my code for ImgAreaSelect :

    <!DOCTYPE html>
    <html>
    <head>         
      <link rel="stylesheet" type="text/css" href="css/imgareaselect-default.css" />
      <script type="text/javascript" src="scripts/jquery.min.js"></script>
      <script type="text/javascript" src="scripts/jquery.imgareaselect.pack.js">    </script>      
        <script type="text/javascript">
        $(document).ready(function () {
      $('#ladybug_ant').imgAreaSelect({ maxWidth: 200, maxHeight: 150, handles: true });
    });    

    </script>
    </head>
    <body>

   <img src="http://jotform.org/demo/jquery-image-area-select-plugin/images/sweet-dogs.jpg" id="ladybug_ant" style="height:200px;width:300px;"><br>


</body>
</html>

this code i written for select image area by ImgAreaSelect.now i want selected image in new div.I hope you understand what i want to ask.

like image 390
sonalgoyal Avatar asked Nov 02 '22 09:11

sonalgoyal


1 Answers

The answer is here: http://odyniec.net/projects/imgareaselect/examples-callback.html - with live example!!

    function preview(img, selection) {
    var scaleX = 100 / (selection.width || 1);
    var scaleY = 100 / (selection.height || 1);

    $('#ferret + div > img').css({
        width: Math.round(scaleX * 400) + 'px',
        height: Math.round(scaleY * 300) + 'px',
        marginLeft: '-' + Math.round(scaleX * selection.x1) + 'px',
        marginTop: '-' + Math.round(scaleY * selection.y1) + 'px'
    });
}

$(document).ready(function () {
    $('<div><img src="ferret.jpg" style="position: relative;" /><div>')
        .css({
            float: 'left',
            position: 'relative',
            overflow: 'hidden',
            width: '100px',
            height: '100px'
        })
        .insertAfter($('#ferret'));

    $('#ferret').imgAreaSelect({ aspectRatio: '1:1', onSelectChange: preview });
});

Hope I could help. :)

like image 107
Mr.TK Avatar answered Nov 14 '22 02:11

Mr.TK