UNPKG

@daysnap/utils

Version:
19 lines (17 loc) 432 B
// src/compressImage.ts async function compressImage(image, mw) { let { width, height } = image; const scale = width / height; if (mw && width > mw) { width = mw; height = width / scale; } const canvas = document.createElement("canvas"); const ctx = canvas.getContext("2d"); Object.assign(canvas, { width, height }); ctx.drawImage(image, 0, 0, width, height); return canvas; } export { compressImage };