canvasToBlob.ts 339 B

123456789101112131415
  1. /**
  2. * Save a <canvas> element's content to a Blob object.
  3. *
  4. * @param {HTMLCanvasElement} canvas
  5. * @returns {Promise}
  6. */
  7. export default function canvasToBlob(
  8. canvas: HTMLCanvasElement,
  9. type: string,
  10. quality?: number,
  11. ): Promise<Blob | null> {
  12. return new Promise((resolve) => {
  13. canvas.toBlob(resolve, type, quality)
  14. })
  15. }