mirror of
https://github.com/misskey-dev/misskey.git
synced 2024-12-28 01:30:23 +01:00
promiseがコールバックを待たないのを修正
This commit is contained in:
parent
1a3e96bf7f
commit
88e0b522ea
1 changed files with 133 additions and 132 deletions
|
@ -113,7 +113,8 @@ export function canPreview(config: Partial<WatermarkConfig | WatermarkUserConfig
|
|||
* @param el ウォーターマークを適用するキャンバス
|
||||
* @param config ウォーターマークの設定
|
||||
*/
|
||||
export async function applyWatermark(img: string | Blob, el: HTMLCanvasElement, config: WatermarkConfig | null) {
|
||||
export function applyWatermark(img: string | Blob, el: HTMLCanvasElement | OffscreenCanvas, config: WatermarkConfig | null) {
|
||||
return new Promise<void>(async (resolve) => {
|
||||
const canvas = el;
|
||||
const ctx = canvas.getContext('2d')!;
|
||||
const imgEl = new Image();
|
||||
|
@ -232,6 +233,8 @@ export async function applyWatermark(img: string | Blob, el: HTMLCanvasElement,
|
|||
}
|
||||
ctx.drawImage(watermark, x, y, width, height);
|
||||
}
|
||||
|
||||
resolve();
|
||||
};
|
||||
|
||||
let watermarkUrl: string;
|
||||
|
@ -248,11 +251,13 @@ export async function applyWatermark(img: string | Blob, el: HTMLCanvasElement,
|
|||
}
|
||||
}
|
||||
};
|
||||
|
||||
if (typeof img === 'string') {
|
||||
imgEl.src = img;
|
||||
} else {
|
||||
imgEl.src = URL.createObjectURL(img);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -262,12 +267,8 @@ export async function applyWatermark(img: string | Blob, el: HTMLCanvasElement,
|
|||
* @param config ウォーターマークの設定
|
||||
* @returns ウォーターマークを適用した画像のBlob
|
||||
*/
|
||||
export function getWatermarkAppliedImage(img: Blob, config: WatermarkConfig): Promise<Blob> {
|
||||
export async function getWatermarkAppliedImage(img: Blob, config: WatermarkConfig): Promise<Blob> {
|
||||
const canvas = document.createElement('canvas');
|
||||
applyWatermark(img, canvas, config);
|
||||
return new Promise<Blob>(resolve => {
|
||||
canvas.toBlob(blob => {
|
||||
resolve(blob!);
|
||||
});
|
||||
});
|
||||
await applyWatermark(img, canvas, config);
|
||||
return new Promise(resolve => canvas.toBlob(blob => resolve(blob!)));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue