Note that there are some explanatory texts on larger screens.

plurals
  1. POLoader image not showing up when canvas rotating and resizing operation is going on selected file
    primarykey
    data
    text
    <p>I have created sample code here <a href="http://jsfiddle.net/kamlesh_bhure/YpejU/" rel="nofollow">http://jsfiddle.net/kamlesh_bhure/YpejU/</a> where i am rotating image and resizing it as per max height and width.</p> <p>Before starting this process I am showing mask with loading image and hiding it after completing it. But I am not able to see this loader on mobile device or on desktop browser even though I used large image.</p> <p>Also I want to show loading image till browser complete its rendering of processed image.</p> <p>Thanks in advance.</p> <pre><code>&lt;!-- HTML Code --&gt; &lt;div id="mask" class="newLoaderMask"&gt; &lt;img src="http://jimpunk.net/Loading/wp-content/uploads/loading1.gif" width="200" id="loader" /&gt; &lt;/div&gt; &lt;input type="file" accept="image/*" id="takePictureField" /&gt; &lt;div class="captureInsuPanel"&gt; &lt;img id="yourimage" class="imgWeightHght" width="500" /&gt; &lt;/div&gt; &lt;canvas id="hidden_canvas_old"&gt;&lt;/canvas&gt; &lt;canvas id="hidden_canvas_new"&gt;&lt;/canvas&gt; &lt;style&gt; #yourimage { width:100%; } .imgWeightHght { height: 290px !important; width: 220px !important; } .captureInsuPanel img { height: auto; width: auto; } .newLoaderMask { display: none; background: #E5E5E5; position: fixed; left: 0; top: 0; z-index: 10; width: 100%; height: 100%; opacity: 0.8; z-index: 999; } &lt;/style&gt; &lt;script&gt; //Js Code $(document).ready(function () { $("#takePictureField").on("change", gotPic); }); function gotPic(event) { if (event.target.files.length == 1 &amp;&amp; event.target.files[0].type.indexOf("image/") == 0) { var image = event.target.files[0]; $("#yourimage").attr("src", URL.createObjectURL(image)); drawRotatedImage(image, 90, 800, 1000); } } function drawRotatedImage(image, angle, max_width, max_height) { //show loading mask $('#mask').show(); var fileLoader = new FileReader(), imageObj = new Image(); if (image.type.indexOf("image/") == 0) { fileLoader.readAsDataURL(image); } else { alert('File is not an image'); } fileLoader.onload = function () { var data = this.result; imageObj.src = data; }; fileLoader.onabort = function () { alert("The upload was aborted."); }; fileLoader.onerror = function () { alert("An error occured while reading the file."); }; // set up the images onload function which clears the hidden canvas context, // draws the new image then gets the blob data from it imageObj.onload = function () { var imgWidth = this.width; var imgHeight = this.height; rotateAndResize(this, imgWidth, imgHeight); }; function rotateAndResize(image, imgWidth, imgHeight) { var canvas = document.getElementById("hidden_canvas_old"), ctx = canvas.getContext("2d"); var widthHalf = imgWidth / 2, heightHalf = imgHeight / 2; canvas.width = imgWidth; canvas.height = imgWidth; ctx.clearRect(0, 0, canvas.width, canvas.height); ctx.save(); ctx.translate(canvas.width / 2, canvas.height / 2); ctx.rotate(angle * Math.PI / 180); ctx.drawImage(image, -widthHalf, -widthHalf); ctx.restore(); var tempCanvas = document.getElementById("hidden_canvas_new"), tCtx = tempCanvas.getContext("2d"); tempCanvas.width = imgHeight; tempCanvas.height = imgWidth; /* * Crop rotated image from old canvas to remove white space * So that canvas will have only image content without extra padding */ tCtx.drawImage(canvas, canvas.width - imgHeight, 0, imgHeight, imgWidth, 0, 0, imgHeight, imgWidth); tCtx.restore(); /** * Resizing Rotated image */ // calculate the width and height, constraining the proportions if (imgWidth &gt; imgHeight) { if (imgWidth &gt; max_width) { imgHeight = Math.round(imgHeight *= max_width / imgWidth); imgWidth = max_width; } } else { if (imgWidth &gt; max_height) { imgWidth = Math.round(imgWidth *= max_height / imgHeight); imgHeight = max_height; } } var tempCanvasTemp = tempCanvas; tempCanvas.remove(); canvas.remove(); var tempCanvas1 = document.createElement("canvas"), tCtx1 = tempCanvas1.getContext("2d"); tempCanvas1.id = 'hidden_canvas_new'; //tempCanvas1.style.display = 'none'; tempCanvas1.width = imgHeight; tempCanvas1.height = imgWidth; tCtx1.drawImage(tempCanvasTemp, 0, 0, imgHeight, imgWidth); tCtx1.restore(); document.body.appendChild(tempCanvas1); $("#yourimage").attr("src", tempCanvas1.toDataURL('image/jpeg')); } //hide loading mask $('#mask').hide(); } &lt;/script&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload