Skip to main content

exportAsync

Exports the node as an encoded image.

Signature

exportAsync(settings?: ExportSettings): Promise<Uint8Array>

Parameters

settings

When this parameter is absent, this function defaults to exporting as a PNG at 1x resolution.

Note that the result is a Uint8Array, representing the bytes of the image file (encoded in the specified format).

Create a hexagon, export as PNG, and place on canvas
(async () => {
const polygon = figma.createPolygon()
polygon.pointCount = 6
polygon.fills = [{ type: 'SOLID', color: { r: 1, g: 0, b: 0 } }]

// Export a 2x resolution PNG of the node
const bytes = await polygon.exportAsync({
format: 'PNG',
constraint: { type: 'SCALE', value: 2 },
})

// Add the image onto the canvas as an image fill in a frame
const image = figma.createImage(bytes)
const frame = figma.createFrame()
frame.x = 200
frame.resize(200, 230)
frame.fills = [{
imageHash: image.hash,
scaleMode: "FILL",
scalingFactor: 1,
type: "IMAGE",
}]
})()
Export a VectorNode as an SVG string
 (async () => {
// Create a triangle using the VectorPath API
const vector = figma.createVector()
vector.vectorPaths = [{
windingRule: "EVENODD",
data: "M 0 100 L 100 100 L 50 0 Z",
}]

// Export the vector to SVG
const bytes = await vector.exportAsync({ format: 'SVG' })
// Decode the bytes into an SVG string
const svg = (new TextDecoder()).decode(bytes);
console.log(svg);
})()