mirror of
https://github.com/signalapp/Signal-Desktop.git
synced 2026-04-23 01:48:13 +01:00
Edit profile
This commit is contained in:
28
ts/util/imagePathToArrayBuffer.ts
Normal file
28
ts/util/imagePathToArrayBuffer.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
// Copyright 2021 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { canvasToArrayBuffer } from './canvasToArrayBuffer';
|
||||
|
||||
export async function imagePathToArrayBuffer(
|
||||
src: string
|
||||
): Promise<ArrayBuffer> {
|
||||
const image = new Image();
|
||||
const canvas = document.createElement('canvas');
|
||||
const context = canvas.getContext('2d');
|
||||
if (!context) {
|
||||
throw new Error(
|
||||
'imagePathToArrayBuffer: could not get canvas rendering context'
|
||||
);
|
||||
}
|
||||
|
||||
image.src = src;
|
||||
await image.decode();
|
||||
|
||||
canvas.width = image.width;
|
||||
canvas.height = image.height;
|
||||
|
||||
context.drawImage(image, 0, 0);
|
||||
|
||||
const result = await canvasToArrayBuffer(canvas);
|
||||
return result;
|
||||
}
|
||||
Reference in New Issue
Block a user