Capture an element in high resolution
Control pixel density and output size without changing the live component’s CSS.
Use dpr for raster pixel density and scale to multiply the output dimensions. Downloads use DPR 1, so use scale for higher-resolution files.
Export at a higher pixel density
Install @zumer/snapdom, select the rendered element, and capture it:
import { snapdom } from '@zumer/snapdom'
const image = await snapdom.toPng(element, {
dpr: 2,
scale: 1.5,
backgroundColor: '#ffffff',
embedFonts: true,
})Size and sharpness are separate settings
dpr changes raster pixel density. scale changes output dimensions when neither width nor height is set. Explicit dimensions take precedence over scale; use the smallest output that meets your destination requirement.
Compare normal and 2× output
Capture the same target with the default settings or fixed DPR 2 and compare pixel dimensions.
Resolution test
Fine text and one-pixel rules reveal the output density.
Limits and common mistakes
Doubling width and height produces four times as many pixels. Very high DPR values can exceed canvas limits for image previews and canvas exports. For large PNG or JPEG files, use the automatic file-export path. download() always uses DPR 1, so pass scale (for example scale: devicePixelRatio) for a sharper downloaded file.
Frequently asked questions
Should I use DPR or scale?
Use DPR for sharper raster output at the same CSS size; use scale to enlarge the capture itself. Downloads always use DPR 1, so use scale for a sharper downloaded file.
Does SVG need a high DPR?
SVG preserves scalable content, but embedded images and canvas snapshots retain their source resolution. DPR affects raster exports such as PNG, JPEG, WebP and Canvas.