Right use of the toBlob function
This commit is contained in:
parent
2279169018
commit
aa07c719d3
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue