canvas resize canvas
(window.onresize = () => {
canvas.width = innerWidth, canvas.height = innerHeight;
})();
canvas resize canvas
(window.onresize = () => {
canvas.width = innerWidth, canvas.height = innerHeight;
})();
how to stop canvas resizing from resizing images
//You just need to calculate the image aspect ratio:
var f = image.height / image.width;
var newHeight = canvas.width * f;
//And then draw using the recalculated height of image for destination:
ctx.drawImage(image, 0, 0, image.width, image.height, // source size
0, 0, canvas.width, newHeight); // destination size
//Canvas will do the clipping for you.
//If you want to lets say center the destination vertical position you can do:
var destY = (canvas.height - image.height) / 2;
ctx.drawImage(image, 0, 0, image.width, image.height, // source size
0, destY, canvas.width, newHeight); // destination size
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us