Last active
March 1, 2021 04:37
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
function compressImage(image, scale, initalWidth, initalHeight){ | |
return new Promise((resolve, reject) => { | |
const canvas = document.createElement("canvas"); | |
canvas.width = scale * initalWidth; | |
canvas.height = scale * initalHeight; | |
const ctx = canvas.getContext("2d"); | |
ctx.drawImage(image, 0, 0, canvas.width, canvas.height); | |
ctx.canvas.toBlob((blob) => { | |
resolve(blob); | |
}, "image/png"); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment