signal-desktop/ts/util/canvasToBytes.ts

15 lines
426 B
TypeScript
Raw Normal View History

// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
2021-06-25 16:08:16 +00:00
import { canvasToBlob } from './canvasToBlob';
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());
}