Cropbox help required please
I am having problems with cropbox. The image loads ok and dragging and cropping works but not zooming in then cropping. You only get part of the image which isn't zoomed in. I can only find one example which isn't helpful. There is no image to start with until you have browsed and selected one. This is my function. Thanks
- $( function () {
- $('#search_image').on('change', function(){
- str = document.getElementById("search_image").value;
- var res = str.substring(str.length - 3);
- res = res.toLowerCase();
- $( "#search_image_error" ).replaceWith( "<div class='error' id='search_image_error'></div>" );
- if (res == "jpg" | res == "png") {
- var temp_files = document.getElementById("search_image");
- var files = temp_files.files;
- filesearch_image_size = files[0].size
- if (files[0].size > 8192 * 1024) {
- $( "#search_image_error" ).replaceWith( "<div class='error' id='search_image_error'>The image is over 10mg - please use a smaller one</div>" );
- document.getElementById("search_image").value = "";
- }
- else {
- file1_size = 0;
- file2_size = 0;
- file3_size = 0;
- file4_size = 0;
- file5_size = 0;
- file6_size = 0;
- fileoperatorlogo_image_size = 0;
- temp_files = document.getElementById("browse_file1");
- files = temp_files.files;
-
- if (files.length > 0) {
- file1_size = files[0].size;
- }
- temp_files = document.getElementById("browse_file2");
- files = temp_files.files;
- if (files.length > 0) {
- file2_size = files[0].size;
- }
- temp_files = document.getElementById("browse_file3");
- files = temp_files.files;
- if (files.length > 0) {
- file3_size = files[0].size;
- }
- temp_files = document.getElementById("browse_file4");
- files = temp_files.files;
- if (files.length > 0) {
- file4_size = files[0].size;
- }
- temp_files = document.getElementById("browse_file5");
- files = temp_files.files;
- if (files.length > 0) {
- file5_size = files[0].size;
- }
- temp_files = document.getElementById("browse_file6");
- files = temp_files.files;
- if (files.length > 0) {
- file6_size = files[0].size;
- }
- file_total_size = file1_size + file2_size + file3_size + file4_size + file5_size + file6_size + filesearch_image_size + fileoperatorlogo_image_size;
- if (file_total_size > 8192 * 1024) {
- $( "#search_image_error" ).replaceWith( "<div class='error' id='search_image_error'>The total size of all the images to be uploaded is over 10mg - please use smaller ones or upload a few at a time</div>" );
- document.getElementById("search_image").value = "";
- }
- else {
- var reader = new FileReader();
- reader.onload = function(e) {
- var image = new Image();
- image.src = e.target.result;
-
- image.onload = function() {
- the_imagewidth = image.width;
- the_imageheight = image.height;
-
- if (parseInt(the_imagewidth) >= 400 & parseInt(the_imageheight) >= 460) {
- $( "#the_crop_image_remove" ).replaceWith( "" );
- $( '#cropimage' ).attr('src', e.target.result);
- $( '#the_crop_image' ).prepend("<a href='JavaScript: remove_search_image();' class='delete' id='the_crop_image_remove'>X</a>");
- }
- else {
- $( "#search_image_error" ).replaceWith( "<div class='error' id='search_image_error'>The width should be at least 400px and the height at least 460px</div>" );
- document.getElementById("search_image").value = "";
- }
- };
- }
- }
-
- reader.readAsDataURL(this.files[0]);
-
- $( '#cropimage' ).on('load', function() {
- var image = $(this),
- cropwidth = image.attr('cropwidth'),
- cropheight = image.attr('cropheight'),
-
- results = image.next('.results' );
-
- image.cropbox( {width: cropwidth, height: cropheight, showControls: 'auto' } )
- .on('cropbox', function( event, results, img ) {
-
- $("#theHiddenX").val ( results.cropX );
- $("#theHiddenY").val ( results.cropY );
- $("#theHiddenW").val ( results.cropW );
- $("#theHiddenH").val ( results.cropH );
-
- });
- } );
- }
- }
- else {
- $( "#search_image_error" ).replaceWith( "<div class='error' id='search_image_error'>Please select a valid jpg or png file</div>" );
- }
- });
- } );