Skip to content

Commit e6c7310

Browse files
committed
Scale blur radius to match preview and export, increase blur intensity
Blur and oil paint radii now scale by spatialScale so the 1200px preview matches the full-res export. Increased blur base from /10 to /4 for a more usable intensity range.
1 parent 9cb8255 commit e6c7310

1 file changed

Lines changed: 21 additions & 4 deletions

File tree

frontend/src/lib/utils/canvas-filters.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,19 @@ export function applyFilters(
106106
w = Math.round(srcW * (h / srcH));
107107
}
108108

109+
// Remember full-res dimensions before capping — spatial effects (blur,
110+
// oil paint) scale their radius by this ratio so the preview at maxSize
111+
// matches the final export pixel-for-pixel.
112+
const fullLong = Math.max(w, h);
113+
109114
if (maxSize > 0 && (w > maxSize || h > maxSize)) {
110115
const scale = maxSize / Math.max(w, h);
111116
w = Math.round(w * scale);
112117
h = Math.round(h * scale);
113118
}
114119

120+
const spatialScale = Math.max(w, h) / fullLong;
121+
115122
const canvas = document.createElement('canvas');
116123
canvas.width = w;
117124
canvas.height = h;
@@ -133,14 +140,24 @@ export function applyFilters(
133140
ctx.imageSmoothingEnabled = true;
134141
}
135142

136-
// Blur (two-pass box blur)
143+
// Blur (two-pass box blur) — radius scaled to match full-res output
137144
if (filters.blur > 0) {
138-
boxBlur(ctx, w, h, Math.max(1, Math.round(filters.blur / 10)));
145+
boxBlur(
146+
ctx,
147+
w,
148+
h,
149+
Math.max(1, Math.round((filters.blur / 4) * spatialScale))
150+
);
139151
}
140152

141-
// Oil paint (heavier box blur)
153+
// Oil paint (heavier box blur) — radius scaled to match full-res output
142154
if (filters.oilPaint > 0) {
143-
boxBlur(ctx, w, h, Math.max(2, Math.round(filters.oilPaint * 2)));
155+
boxBlur(
156+
ctx,
157+
w,
158+
h,
159+
Math.max(2, Math.round(filters.oilPaint * 2 * spatialScale))
160+
);
144161
}
145162

146163
// Build the palette-grade LUT once, if needed. Output depends only on source

0 commit comments

Comments
 (0)