Skip to content

cy.jpg(options?)

cy.jpg — Core > Export and snapshots > Image export. Cytoscape.js signatures, parameters and return contract.

cy.jpg — Core › Export and snapshots › Image export

Preview · Core › Export and snapshots › Image export

Read in the complete API reference · All API members

// Export as JPEG: as {@link png}, plus quality (0..1) and a white default bg (JPEG has no alpha channel)
cy.jpg(options?: ExportOptions): Promise<string | Blob>

Export as JPEG: as png, plus quality (0..1) and a white default bg (JPEG has no alpha channel).

Parameters
NameDescription
options: ExportOptions?Default: {}

as png, plus quality

Fields of options
NameDescription
output: 'base64uri' | 'base64' | 'blob' | 'blob-promise'?

result form: a data-URI string (default), the raw base64 payload, or a Blob ('blob-promise' is accepted as an alias of 'blob' — every output form resolves through the returned promise)

bg: string?

background color under the graph (any CSS color). Default: transparent for png; white for jpg (JPEG has no alpha)

full: boolean?

export the whole graph's bounds instead of the current viewport (default false)

scale: number?

output pixels per rendered CSS px (viewport export) or per model unit (full export); default 1. Ignored when maxWidth/maxHeight are given

maxWidth: number?

cap the output width in px (the scale is computed to fit; overrides scale)

maxHeight: number?

cap the output height in px (the scale is computed to fit; overrides scale)

quality: number?

jpg only: encode quality in [0, 1] (default: the browser's)

Returns Promise<string | Blob>

the encoded image in the requested output form

Example

// Use a mounted, renderer-ready core.
await cy.ready;
const image = await cy.jpg({ output: 'blob' });
console.log(image.type); // image/jpeg

Example graph and handle setup

Also spelled cy.jpeg.