diff --git a/src/themes/d4science/account/account.ftl b/src/themes/d4science/account/account.ftl index 40c86e4..18ba289 100644 --- a/src/themes/d4science/account/account.ftl +++ b/src/themes/d4science/account/account.ftl @@ -135,24 +135,24 @@ ctx = canvas.getContext("2d"); ctx.drawImage(img, 0, 0, width, height); - var imageBlob = canvas.toBlob("image/png"); - - var form = document.getElementById('theForm') - var formData = new FormData(form) - // Deleting the big image from the form data to prevent send - formData.delete('imageSelector') - // Adding new blob with new image with right size - formData.append("image", imageBlob); - var xhr = new XMLHttpRequest(); - xhr.onreadystatechange = function() { - if (xhr.readyState == 4 && xhr.status == 200) { - location.reload(); - } else { - alert('An error occurred uploading avatar image') - } - }; - xhr.open(form.method, form.action, true); - xhr.send(formData); + canvas.toBlob(function(blob) { + var form = document.getElementById('theForm') + var formData = new FormData(form) + // Deleting the big image from the form data to prevent send + formData.delete('imageSelector') + // Adding new blob with new image with right size + formData.append("image", blob); + var xhr = new XMLHttpRequest(); + xhr.onreadystatechange = function() { + if (xhr.readyState == 4 && xhr.status == 200) { + location.reload(); + } else { + alert('An error occurred uploading avatar image') + } + }; + xhr.open(form.method, form.action, true); + xhr.send(formData); + }); } // img.onload } // Load files into file reader