Last active
May 15, 2020 13:45
-
-
Save andion/9deaf1a44ca09d9c3b9954264c1c85cd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const resizeToWidth = 800; | |
const resizeToHeight = 600; | |
const canvas = document.getElementById("canvas"); | |
const image = document.getElementById("source"); | |
const ctx = canvas.getContext("2d"); | |
// Get *real* image size with naturalXXX | |
const {naturalWidth: imageWidth, naturalHeight: imageHeight} = image; | |
// Set the canvas to the desired size | |
canvas.width = resizeToWidth; | |
canvas.height = resizeToHeight; | |
// Paste our whole image on the the canvas | |
ctx.drawImage(image, 0, 0, resizeToWidth, resizeToHeight); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment