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
Also in JavaScript:
- how to chunk a base 64 in javascript
- document.print js
- js delete all array items
- action checkbox selected vue js
- how to exclude a specefic tagname from a javascript query search
- javascript find prime number
- firebase realtime database query where number bigger
- javascript floor
- js get class property
- javascript validate date
- javascript replace newline
- js string
- chart js radar grid color
- javascript for loops
- jquery set hidden field value
- moment js
- node.js 8 has been deprecated. firebase functions
- react responsive video player
- how to handle ajax calls in selenium
- optional arguments javascript
- jquery validator Url
- create an observabloe js
- jquery set att
- get combinations of two js