diff --git a/src/index.ts b/src/index.ts index e7a65e2b..37fc559b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -25,6 +25,14 @@ export type Options = { * A string value for the background color, any valid CSS color value. */ backgroundColor?: string + /** + * Width in pixels to be applied to canvas on export. + */ + canvasWidth?: number + /** + * Height in pixels to be applied to canvas on export. + */ + canvasHeight?: number /** * An object whose properties to be copied to node's style before rendering. */ @@ -76,6 +84,7 @@ export type Options = { function getImageSize(domNode: HTMLElement, options: Options = {}) { const width = options.width || getNodeWidth(domNode) const height = options.height || getNodeHeight(domNode) + return { width, height } } @@ -107,10 +116,13 @@ export async function toCanvas( const ratio = options.pixelRatio || getPixelRatio() const { width, height } = getImageSize(domNode, options) - canvas.width = width * ratio - canvas.height = height * ratio - canvas.style.width = `${width}` - canvas.style.height = `${height}` + const canvasWidth = options.canvasWidth || width + const canvasHeight = options.canvasHeight || height + + canvas.width = canvasWidth * ratio + canvas.height = canvasHeight * ratio + canvas.style.width = `${canvasWidth}` + canvas.style.height = `${canvasHeight}` if (options.backgroundColor) { context.fillStyle = options.backgroundColor