()
| 23 | const ctx = canvas.getContext('2d') |
| 24 | |
| 25 | const compress = () => { |
| 26 | canvas.width = width |
| 27 | canvas.height = height |
| 28 | ctx?.clearRect(0, 0, width, height) |
| 29 | ctx?.drawImage(img, 0, 0, width, height) |
| 30 | |
| 31 | const dataUrl = canvas.toDataURL(file.type, quality) |
| 32 | const base64 = dataUrl.split(',')[1] |
| 33 | return { base64, size: base64.length * 0.75 } |
| 34 | } |
| 35 | |
| 36 | let { base64, size } = compress() |
| 37 |