

You made the error, for the second call, to set the size of source to the size of the target.Īnyway i bet that you want the same aspect ratio for the scaled image, so you need to compute it : var hRatio = canvas.width / img.width What am I missing here? Can anyone point me in the right direction please? I need to maintain that size to pass beck to the server when the form is submitted, but only want a smaller view of it to appear in the canvas for the user. So for the code above, the width and heights are 1142x856, as that is the final image size.

I need the whole image 'scaled' to fit on the canvas, despite the actual image size being larger than the 320x240 canvas size. I only get part of the image on the canvas, in this case the top left corner. where canvas.width and canvas.height is the image height and width x a scaling factor based on the size of the original image.īut when I go to use the code: ctx.drawImage(img, 0, 0, canvas.width, canvas.height, 0, 0, canvas.width, canvas.height This code will render the scaled image on the canvas, with the canvas of size 320 x 240px: ctx.drawImage(img, 0, 0, canvas.width, canvas.height) To do this, we place it on the canvas and manipulate it there. Once the image is loaded, we perform some scaling on it in order to reduce its filesize before we pass it back to the server.

I have a form that allows a user to upload an image.
