Skip to content

Commit 10cc6c9

Browse files
committed
fix: capture at exact CSS pixel dimensions (scale:1) to avoid retina 2x pixelation
1 parent ff8d6a5 commit 10cc6c9

4 files changed

Lines changed: 13 additions & 7 deletions

File tree

app/src/components/bulk-canvas-card.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ onMounted(() => {
160160
.card__render-inner {
161161
transform-origin: top left;
162162
pointer-events: none;
163+
image-rendering: -webkit-optimize-contrast;
163164
}
164165
165166
.card__placeholder {

app/src/snapdom.d.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
declare module '@zumer/snapdom' {
2+
interface SnapdomOptions {
3+
scale?: number
4+
}
25
interface ToBlobOptions {
36
type?: string
47
scale?: number
58
}
69
interface SnapdomResult {
710
toBlob(options?: ToBlobOptions): Promise<Blob>
11+
toCanvas(options?: { scale?: number }): Promise<HTMLCanvasElement>
812
toPng(): Promise<HTMLImageElement>
913
}
10-
export function snapdom(element: HTMLElement): Promise<SnapdomResult>
14+
export function snapdom(element: HTMLElement, options?: SnapdomOptions): Promise<SnapdomResult>
1115
}

app/src/views/BuilderView.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,10 @@ async function exportPng() {
205205
const origT = wrapper!.style.transform
206206
wrapper!.style.transform = 'none'
207207
208-
// Capture with snapdom at native resolution
209-
const result = await snapdom(thumb) as any
210-
const canvas = await result.toCanvas()
211-
const blob = await new Promise<Blob>((resolve) => canvas.toBlob((b: Blob) => resolve(b), 'image/png'))
208+
// Capture at exact CSS pixel dimensions (scale:1 avoids retina 2x)
209+
const result = await snapdom(thumb, { scale: 1 })
210+
const canvas = await result.toCanvas({ scale: 1 })
211+
const blob = await new Promise<Blob>((resolve) => canvas.toBlob((b) => resolve(b!), 'image/png'))
212212
213213
// Restore transform
214214
wrapper!.style.transform = origT

app/src/views/BulkCreateView.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ async function captureCanvas(id: string): Promise<{ id: string; canvas: HTMLCanv
3737
}))
3838
3939
const { snapdom } = await import('@zumer/snapdom')
40-
const result = await snapdom(thumb) as any
41-
const c = await result.toCanvas() as HTMLCanvasElement
40+
// scale:1 ensures we capture at exact CSS pixel dimensions (not retina 2x)
41+
const result = await snapdom(thumb, { scale: 1 })
42+
const c = await result.toCanvas({ scale: 1 }) as HTMLCanvasElement
4243
4344
// Restore
4445
if (scaleEl) scaleEl.style.transform = origTransform

0 commit comments

Comments
 (0)