Skip to content

useExport

Provides functions to export the canvas as a static image or a video file.

Import

ts
import { useExport, downloadURI, downloadBlob } from '@asset-studio/core'

Usage

tsx
function ExportPanel() {
  const { exportImage, exportVideo, isExporting } = useExport()

  return (
    <div>
      <button onClick={() => downloadURI(exportImage(2), 'my-design.png')} disabled={isExporting}>
        Export PNG
      </button>
      <button
        onClick={async () => {
          const blob = await exportVideo(2, 30)
          if (blob) downloadBlob(blob, 'my-video.mp4')
        }}
        disabled={isExporting}
      >
        {isExporting ? 'Exporting...' : 'Export Video'}
      </button>
    </div>
  )
}

Return Value

Property / FunctionTypeDescription
isExportingbooleantrue while an export is in progress.
exportImage(pixelRatio?: number) => stringExport the canvas as a PNG data URL.
exportVideo(pixelRatio?: number, fps?: number) => Promise<Blob | null>Export the canvas timeline as an MP4 blob.

exportImage Parameters

ParameterTypeDefaultDescription
pixelRationumber1Pixel density multiplier. Use 2 for Retina/2x output.

exportVideo Parameters

ParameterTypeDefaultDescription
pixelRationumber1Pixel density multiplier. Use 2 for Retina/2x output.
fpsnumber30Frames per second for the exported video.

Notes

  • exportImage returns a PNG data URL — use downloadURI to trigger a download.
  • exportVideo returns a Blob (or null on failure) — use downloadBlob to trigger a download.
  • Video export uses the mediabunny engine and records each frame of the full timeline.

Released under a proprietary license.