I am loading an image and then drawing that image to a canvas. I am also scaling the image down to fit the canvas. When I do this, the image draws onto the canvas at the proper width but the height is about 1/4 of what the canvas' actual height is.
//Calculate height from canvas-to-image width ratio
var width = canvas.width;
var height = ( width / img.width ) * img.height;
//Draw scale image (This results in a squished height, despite "height" being correct)
context.drawImage( image, 0, 0, img.width, img.height, 0, 0, width, height );
Even though height
is correct (checked in console), the image draws to the canvas at a much smaller height.
Also, when I check the ratio of the canvas.width / canvas.height
vs img.width / img.height
I get: .707234
vs .707818
. That's so close it could not account for the huge height problem.
Why does this happen? How do I fix this?
EDIT: On Chrome, this exact code shows correctly.