diff --git a/packages/frontend/src/components/MkGalleryPostPreview.vue b/packages/frontend/src/components/MkGalleryPostPreview.vue
index d694dcce35..8be9dd25a2 100644
--- a/packages/frontend/src/components/MkGalleryPostPreview.vue
+++ b/packages/frontend/src/components/MkGalleryPostPreview.vue
@@ -54,20 +54,16 @@ function leaveHover(): void {
diff --git a/packages/frontend/src/workers/draw-blurhash.ts b/packages/frontend/src/workers/draw-blurhash.ts
index cbf8d39d72..e85303fed4 100644
--- a/packages/frontend/src/workers/draw-blurhash.ts
+++ b/packages/frontend/src/workers/draw-blurhash.ts
@@ -1,24 +1,18 @@
import { decode } from 'blurhash';
-let canvas: OffscreenCanvas | null = null;
-
-onmessage = (event) => {
- if ('canvas' in event.data) {
- canvas = event.data.canvas;
- }
- if (!canvas) {
- console.error('Cannot draw blurhash without canvas', canvas, event.data);
- throw new Error('Cannot draw blurhash without canvas');
- }
+onmessage = async (event) => {
if (!('hash' in event.data && typeof event.data.hash === 'string')) {
return;
}
const width = event.data.width ?? 64;
const height = event.data.height ?? 64;
+ const canvas = new OffscreenCanvas(width, height);
const ctx = canvas.getContext!('2d');
if (!ctx) return;
const imageData = ctx.createImageData(width, height);
const pixels = decode(event.data.hash, width, height);
imageData.data.set(pixels);
- ctx!.putImageData(imageData, 0, 0);
+ ctx.putImageData(imageData, 0, 0);
+ const bitmap = canvas.transferToImageBitmap();
+ postMessage(bitmap, [bitmap]);
};