I'm trying to work out img/canvas scaling but it's not working. I've got an image, and I want to compress it, so I'm using canvas to do this using the following code: <img id='srcimg'> <img id='copyimg'> and function doSendToCanvasThenCopyImg(srcimg, destimg) { var scale = 1; var natW = srcimg.naturalWidth; var natH = srcimg.naturalHeight; var newCanvas = document.createElement('canvas'); newCanvas.width = parseInt(natW * scale); newCanvas.height = parseInt(natH * scale); var ctx = newCanvas.getContext("2d"); ctx.drawImage(srcimg, 0, 0, natW, natH, 0, 0, newCanvas.width, newCanvas.height); var base64 = newCanvas.toDataURL('image/jpeg', 1); destimg.src = base64; } and function scaleToFit(img, newW, natW, natH) { var scale = newW / natW; var newCanvas = document.createElement('canvas'); var ctx = newCanvas.getContext("2d"); ctx.drawImage(img, 0, 0, natW, natH, 0, 0,...