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",
}]
})()