From aa07c719d3084463f30f4a13fed57298dd0b88be Mon Sep 17 00:00:00 2001 From: Mauro Mugnaini Date: Fri, 5 Feb 2021 20:08:25 +0100 Subject: [PATCH] Right use of the toBlob function --- src/themes/d4science/account/account.ftl | 36 ++++++++++++------------ 1 file changed, 18 insertions(+), 18 deletions(-) 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