I use Jcrop to edit images uploaded by users, when the user decides to edit their image, an AJAX call is created to get the original image of the user, my code looks like this:
var jcrop_api; $('.edit_image').on('click', function(e) { var url = $(this).attr('data-url'); e.preventDefault(); $.ajax({ url: url, type: 'GET', cache: false, beforeSend: function() { // Remove old box in case user uploaded new image bring the latest one $('#edit_box').remove(); }, success: function(result) { if (result.error) { alert(result.error); } else { $('.edit_image_box').html(result); $('#edit_box').modal({ show: true}); $('#original_img').load( function() { $(this).Jcrop({ aspectRatio: 1, onSelect: updateCoords, boxWidth: 700, boxHeight: 700 }, function() { jcrop_api = this; }); }); } } }) }); function updateCoords(c) { $('#x').val(cx); $('#y').val(cy); $('#w').val(cw); $('#h').val(ch); }; function checkCoords() { if (parseInt($('#w').val())) return true; alert('Please select a crop region then press submit.'); return false; };
The box loads, the modal is displayed, and the image loads fine, but as soon as it finishes loading and Jcrop starts playing, it compresses the width completely, leaving the image about 20 pixels wide.
Can someone please help me with this, in almost 80% of cases this will happen. Hooray!
source share