Skip to content

@fabwcie/free-drawing / utils/image

utils/image ​

Variables ​

maxImageSize ​

const maxImageSize: 2048 = 2048

Defined in: packages/free-drawing/src/utils/image.ts:10

Longest side of an image kept in a drawing (px): bigger images are reduced when added

Functions ​

findImages() ​

findImages(node): Image[]

Defined in: packages/free-drawing/src/utils/image.ts:136

Images of a node (itself, or images of a group or a frame)

Parameters

node

Node

Drawing shape or group

Returns

Image[]

Konva images


getFileId() ​

getFileId(data): Promise<string>

Defined in: packages/free-drawing/src/utils/image.ts:77

Id of an image file: hash of its content (the same image added twice is kept once), random without crypto.subtle (page out of a secure context)

Parameters

data

string

Data URL of the image

Returns

Promise<string>

Id of 32 characters


getFileIds() ​

getFileIds(nodes): string[]

Defined in: packages/free-drawing/src/utils/image.ts:167

Ids of the files of images

Parameters

nodes

Node<NodeConfig>[]

Drawing shapes or groups

Returns

string[]

Ids of their files, each one once


getImagesToLoad() ​

getImagesToLoad(nodes): HTMLImageElement[]

Defined in: packages/free-drawing/src/utils/image.ts:144

Elements of the images of shapes still loading (drawn empty until then): exports wait for them

Parameters

nodes

Node<NodeConfig>[]

Drawing shapes or groups

Returns

HTMLImageElement[]

Elements not loaded yet, each one once


getSvgFiles() ​

getSvgFiles(files): [string, Blob][]

Defined in: packages/free-drawing/src/utils/image.ts:38

SVG images of a drawing of another app (Excalidraw, tldraw): read as images of drawings by readImage, drawings keep raster images only

Parameters

files

unknown

Image files of the converted drawing (not trusted)

Returns

[string, Blob][]

SVG files by id, as blobs


isImageData() ​

isImageData(value): value is string

Defined in: packages/free-drawing/src/utils/image.ts:29

Data URL of an image file that a drawing can keep

Parameters

value

unknown

Value read from a file, a link or another user (not trusted)

Returns

value is string

True for a data URL of a PNG, JPEG, WebP or GIF image of a reasonable size


loadImages() ​

loadImages(elements): Promise<void>

Defined in: packages/free-drawing/src/utils/image.ts:158

Wait for images to be decoded before they are drawn (export right after a drawing is opened or an image added)

Parameters

elements

HTMLImageElement[]

Elements of images, see getImagesToLoad

Returns

Promise<void>

Resolved once each one is decoded, or can't be (drawn empty)


parseFiles() ​

parseFiles(files): DrawingFiles

Defined in: packages/free-drawing/src/utils/image.ts:63

Image files of a drawing, only valid ones (files, links and other users can send anything)

Parameters

files

unknown

Files read (not trusted)

Returns

DrawingFiles

Files with a valid id and data, in a new object


readImage() ​

readImage(source): Promise<DrawingImage>

Defined in: packages/free-drawing/src/utils/image.ts:92

Image of a file chosen or pasted by the user, ready for a drawing: reduced to maxImageSize, encoded as WebP (else PNG with transparency, JPEG without), so it stays small in files, links and collaboration

Parameters

source

Blob

Image file (PNG, JPEG, WebP, GIF, SVG...)

Returns

Promise<DrawingImage>

Data URL and size of the image

Throws

error.notImage when the browser can't read it


setupImages() ​

setupImages(node, files, elements): void

Defined in: packages/free-drawing/src/utils/image.ts:230

Images of a drawing shape shown from the files of the drawing (again when their file changes), drawn as the drawing in dark mode, saved without their element. Called when shapes are added or loaded

Parameters

node

Node

Drawing shape or group

files

ReadonlyMap<string, string>

Files of the drawing

elements

Map<string, HTMLImageElement>

Elements of the files of the drawing, by id

Returns

void