Skip to content

Open-source social media scheduler built for AI agents and the teams behind them. Create, schedule and publish posts to every network through MCP or the REST API, or write them yourself in a composer your team will love.

737 B
Raw Blame
/**
 * A canvas encoded as an image file; rejects when the browser cannot encode it.
 * It imports nothing, so code run outside the bundler (the media editor's
 * preset parity test runs `mediaEditor.ts` in Node) can use it.
 */
export const canvasToFile = (
    canvas: HTMLCanvasElement,
    name: string,
    type: string,
    quality?: number,
): Promise<File> =>
    new Promise((resolve, reject) => {
        canvas.toBlob(
            (blob) => {
                if (!blob) {
                    reject(new Error('The image could not be encoded.'));

                    return;
                }

                resolve(new File([blob], name, { type }));
            },
            type,
            quality,
        );
    });