Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -1211,6 +1211,29 @@ class CanvasConstructor {
}));
}

/**
* Render the canvas into a Data URL.
* @param {string} type the standard MIME type for the image format to return. If you do not specify this parameter, the default value is PNG.
* @param {any[]} args Extra arguments
* @returns {string}
* @see https://github.com/Automattic/node-canvas#canvastodataurl-sync-and-async
*/
toDataURL(type, ...args) {
return this.canvas.toDataURL(type, ...args);
}

/**
* Render the canvas into a Data URL using a Promise.
* @param {string} type the standard MIME type for the image format to return. If you do not specify this parameter, the default value is PNG.
* @returns {Promise<string>}
*/
toDataURLAsync(type) {
return new Promise((resolve, reject) => this.canvas.toDataURL(type, (err, url) => {
if (err) reject(err);
else resolve(url);
}));
}

static getCanvas() {
return Canvas;
}
Expand Down
2 changes: 2 additions & 0 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ declare module 'canvas-constructor' {

public toBuffer(options?: Object): Buffer;
public toBufferAsync(): Promise<Buffer>;
public toDataURL(type: string, ...args: any[]): string;
public toDataURLAsync(type: string): Promise<string>;

public static getCanvas(): NodeCanvas;
public static registerFont(path: string, family: string | fontFaceType);
Expand Down