2021-03-09 19:16:56 +00:00
|
|
|
// Copyright 2021 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2021-06-25 16:08:16 +00:00
|
|
|
import { canvasToBlob } from './canvasToBlob';
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { MIMEType } from '../types/MIME';
|
2021-06-25 16:08:16 +00:00
|
|
|
|
2021-09-24 00:49:05 +00:00
|
|
|
export async function canvasToBytes(
|
2021-08-06 00:17:05 +00:00
|
|
|
canvas: HTMLCanvasElement,
|
|
|
|
mimeType?: MIMEType,
|
|
|
|
quality?: number
|
2021-09-24 00:49:05 +00:00
|
|
|
): Promise<Uint8Array> {
|
2021-08-06 00:17:05 +00:00
|
|
|
const blob = await canvasToBlob(canvas, mimeType, quality);
|
2021-09-24 00:49:05 +00:00
|
|
|
return new Uint8Array(await blob.arrayBuffer());
|
2021-03-09 19:16:56 +00:00
|
|
|
}
|