From a46eb47323c5bc4d420e1fe44d4324d527a83e9f Mon Sep 17 00:00:00 2001 From: Hiren Kangad Date: Tue, 10 Mar 2026 04:02:54 +0530 Subject: [PATCH] fix(refboard): copy to clipboard at native image resolution (up to 4x) Computes resolution multiplier from native texture size vs display size, so a 2000px image shown at 400px on canvas copies close to 2000px. Capped at 4x to avoid excessive memory usage. --- frontend/src/canvas/clipboard.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/frontend/src/canvas/clipboard.ts b/frontend/src/canvas/clipboard.ts index baf58a3..b2604c5 100644 --- a/frontend/src/canvas/clipboard.ts +++ b/frontend/src/canvas/clipboard.ts @@ -83,13 +83,23 @@ export async function writeCanvasToClipboard( tempContainer.addChild(obj); } - // 3. Generate texture at 1x resolution (native pixel size) + // 3. Compute resolution multiplier to approach native texture resolution + // e.g. a 2000px image displayed at 400px → ratio ~5, capped at 4x + let maxRatio = 1; + for (const item of items) { + const tex = (item.displayObject as any)?.texture; + if (tex && tex.width > 1 && item.data.w > 1) { + maxRatio = Math.max(maxRatio, tex.width / item.data.w); + } + } + const resolution = Math.min(Math.max(maxRatio, window.devicePixelRatio || 1), 4); + let texture; let extractedCanvas: HTMLCanvasElement; try { texture = app.renderer.generateTexture({ target: tempContainer, - resolution: 1, + resolution, frame: new Rectangle(0, 0, totalW, totalH), }); extractedCanvas = app.renderer.extract.canvas(texture) as HTMLCanvasElement; @@ -115,7 +125,7 @@ export async function writeCanvasToClipboard( ctx2d.fillRect(0, 0, outputCanvas.width, outputCanvas.height); ctx2d.drawImage(extractedCanvas, 0, 0); } else { - // Full viewport screenshot + // Full viewport screenshot (at device pixel ratio for crisp output) const extractedCanvas = app.renderer.extract.canvas(viewport) as HTMLCanvasElement; outputCanvas = document.createElement('canvas'); outputCanvas.width = extractedCanvas.width;