0

I have JavaScript which sends an image to a server. This works fine but I would like to have the image resized before it is sent. Here is my working code:

function sendFile() {
    var file = document.getElementById('filename').files[0];
    ws.send(document.getElementById('filename').value);

    var reader = new FileReader();
    var rawData = new ArrayBuffer();
    reader.loadend = function () {
    }
    reader.onload = function (e) {
        rawData = e.target.result;
        ws.send(rawData);
        // alert("the File has been transferred.")
    }
    reader.readAsArrayBuffer(file);
}      

How can I resize the image, please?

thelovekesh
  • 1,364
  • 1
  • 8
  • 22
sippytom
  • 27
  • 9
  • Please take a look at this answer https://stackoverflow.com/a/26884245/11634507 – taffy chinX Jul 03 '21 at 07:14
  • Does this answer your question? [Resize a Base-64 image in JavaScript without using canvas](https://stackoverflow.com/questions/20958078/resize-a-base-64-image-in-javascript-without-using-canvas) – Software Engineer Jul 03 '21 at 07:19
  • Thanks for the quick respose but where does the // Use it like that : resizedataURL('yourDataURIHere', 50, 50); function call go? – sippytom Jul 03 '21 at 22:52
  • just a heads up, canvas can increase the size (even after croping/resizeing) https://stackoverflow.com/a/51810740/1008999 – Endless Jul 05 '21 at 17:05

0 Answers0