Skip to content

Instantly share code, notes, and snippets.

@Ramko9999
Last active March 1, 2021 04:37
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