cropbox and upload
cropbox and upload
I can't see what is wrong with this. When I upload an image it is using the height and width of the previous image not the one just uploaded by the look of it. Thanks
- <!DOCTYPE html>
- <html>
- <head>
- <title>jQuery-cropbox</title>
- <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
- <meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1, maximum-scale=1"/>
- <link type="text/css" media="screen" rel="stylesheet" href="jquery.cropbox.css">
- <style type="text/css">
- body {
- font-family : sans-serif;
- font-size : 13px;
- }
- .results {
- font-family : monospace;
- font-size : 20px;
- }
- </style>
- <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
- <script type="text/javascript" src="hammer.js"></script>
- <script type="text/javascript" src="jquery.mousewheel.js"></script>
- <script type="text/javascript" src="jquery.cropbox.js"></script>
- <script type="text/javascript" defer>
-
-
- $( function () {
-
- $( '#cropimage' ).each( function () {
- var image = $(this),
- cropwidth = image.attr('cropwidth'),
- cropheight = image.attr('cropheight'),
- results = image.next('.results' ),
- x = $('.cropX', results),
- y = $('.cropY', results),
- w = $('.cropW', results),
- h = $('.cropH', results);
- image.cropbox( {width: cropwidth, height: cropheight, showControls: 'auto' } )
- .on('cropbox', function( event, results, img ) {
- x.text( results.cropX );
- y.text( results.cropY );
- w.text( results.cropW );
- h.text( results.cropH );
-
- });
- } );
- $('#file').on('change', function(){
- var reader = new FileReader();
- reader.onload = function(e) {
- $( '#cropimage' ).attr('src', e.target.result);
- }
- reader.readAsDataURL(this.files[0]);
- this.files = [];
- $( '#cropimage' ).each( function () {
- var image = $(this),
- cropwidth = image.attr('cropwidth'),
- cropheight = image.attr('cropheight'),
-
- results = image.next('.results' ),
- x = $('.cropX', results),
- y = $('.cropY', results),
- w = $('.cropW', results),
- h = $('.cropH', results);
- image.cropbox( {width: cropwidth, height: cropheight, showControls: 'auto' } )
- .on('cropbox', function( event, results, img ) {
- x.text( results.cropX );
- y.text( results.cropY );
- w.text( results.cropW );
- h.text( results.cropH );
-
- });
- } );
- });
- } );
- </script>
- </head>
- <body>
- <input type="file" id="file">
-
- <img id="cropimage" name="cropimage" alt="" src="img.jpg" cropwidth="461" cropheight="400"/>
-
- <div class="results">
- <b>X</b>: <span class="cropX"></span>
- <b>Y</b>: <span class="cropY"></span>
- <b>W</b>: <span class="cropW"></span>
- <b>H</b>: <span class="cropH"></span>
- </div>
- </body>