Skip to content

@fabwcie/free-drawing / utils/export

utils/export ​

Functions ​

canvasToBlob() ​

canvasToBlob(canvas, type?, quality?): Promise<Blob>

Defined in: packages/free-drawing/src/utils/export.ts:455

Blob of a canvas image

Parameters

canvas

HTMLCanvasElement

rendered image (see renderCanvas)

type?

string = 'image/png'

Mime type of the image (png by default, jpeg for pdf)

quality?

number

quality of lossy formats, from 0 to 1

Returns

Promise<Blob>

promise of the image, rejected when the browser could not create it


createPdf() ​

createPdf(jpeg, width, height, scale): Blob

Defined in: packages/free-drawing/src/utils/export.ts:473

Pdf of one page showing a jpeg image (raster pdf, no library needed)

Parameters

jpeg

Uint8Array<ArrayBuffer>

Image bytes

width

number

Image width in pixels

height

number

Image height in pixels

scale

number

Pixel ratio of image: page has the drawing size (96 dpi)

Returns

Blob

pdf file


getCanvasScale() ​

getCanvasScale(box, scale): number

Defined in: packages/free-drawing/src/utils/export.ts:113

Pixel ratio of an image: the one asked, lowered for a big exported area so the canvas fits in the limits of browsers

Parameters

box

IRect

Exported area

scale

number

Pixel ratio asked

Returns

number

Pixel ratio of the canvas


getExportBox() ​

getExportBox(shapes, layer): IRect | null

Defined in: packages/free-drawing/src/utils/export.ts:36

Box of shapes with padding, in coordinates of their layer, null without shapes

Parameters

shapes

DrawingShape[]

exported shapes (also shapes of groups exported alone)

layer

Container

draw layer, coordinates of the box are relative to it

Returns

IRect | null

box rounded to whole units outwards, null without shapes


renderCanvas() ​

renderCanvas(shapes, box, options?): HTMLCanvasElement

Defined in: packages/free-drawing/src/utils/export.ts:133

Shapes rendered on a canvas (png, pdf, clipboard), same rendering as drawer: clones of shapes in a stage out of page, titles of frames hidden

Parameters

shapes

DrawingShape[]

exported shapes, bottom first (shapes of groups placed as drawn)

box

IRect

Exported area (see getExportBox)

options?

ImageOptions = {}

background, dark mode colors and pixel ratio

Returns

HTMLCanvasElement

canvas of box size multiplied by scale, lowered to fit the canvas limits of browsers (getCanvasScale)


renderSvg() ​

renderSvg(shapes, box, options?): string

Defined in: packages/free-drawing/src/utils/export.ts:433

Shapes as svg (vector) image

Parameters

shapes

DrawingShape[]

exported shapes, bottom first (shapes of groups placed as drawn)

box

IRect

Exported area (see getExportBox), view box of the image

options?

ImageOptions = {}

background and dark mode colors (scale ignored)

Returns

string

svg document


toDarkColor() ​

toDarkColor(color): string

Defined in: packages/free-drawing/src/utils/export.ts:54

Color of dark mode, as css filter invert(93%) hue-rotate(180deg): lightness inverted, hue kept

Parameters

color

string

any CSS color of a shape or background

Returns

string

#rrggbb color, rgba(...) when not opaque (alpha kept)