py4cytoscape.network_views.export_image

export_image(filename=None, type='PNG', resolution=None, units=None, height=None, width=None, zoom=None, network=None, base_url='http://127.0.0.1:1234/v1', *, overwrite_file=False, force_pre_3_10=False, all_graphics_details=None, hide_labels=None, transparent_background=None, export_text_as_font=None, orientation=None, page_size=None)[source]

Save the current network view as an image file.

The image is cropped per the current view in Cytoscape. Consider applying fit_content() prior to export.

Parameters
  • filename (str) – Full path or path relative to current working directory, in addition to the name of the file. Extension is automatically added based on the type argument. If blank, the current network name will be used.

  • type (str) – Type of image to export, e.g., PNG (default), JPEG, PDF, SVG, PS (PostScript).

  • resolution (int) – The resolution of the exported image, in DPI. Valid only for bitmap formats, when the selected width and height ‘units’ is inches. The possible values are: 72 (default), 100, 150, 300, 600. [DEPRECATED as of Cytoscape v3.10]

  • units (str) – The possible values are: pixels (default), inches. [DEPRECATED as of Cytoscape v3.10]

  • height (float) – The height of the exported image. Valid only for bitmap formats, such as PNG and JPEG. [DEPRECATED as of Cytoscape v3.10]

  • width (float) – The width of the exported image. Valid only for bitmap formats, such as PNG and JPEG. [DEPRECATED as of Cytoscape v3.10]

  • zoom (float) – The zoom value to proportionally scale the image. The default value is 100.0. Valid only for bitmap formats, such as PNG and JPEG.

  • network (str or SUID or None) – Name or SUID of the network or view. Default is the “current” network active in Cytoscape. If a network view SUID is provided, then it is validated and returned.

  • base_url (str) – Ignore unless you need to specify a custom domain, port or version to connect to the CyREST API. Default is http://127.0.0.1:1234 and the latest version of the CyREST API supported by this version of py4cytoscape.

  • overwrite_file (bool) – False allows Cytoscape show a message box before overwriting the file if the file already exists; True allows Cytoscape to overwrite it without asking. In Cytoscape v3.10 and later, False causes failure if file already exists.

  • force_pre_3_10 (bool) – True results in pre-Cytoscape 3.10 image export being called, even if Cytoscape can perform the export using more advanced functionality – provided for backward compatibility. The default is False. Available for Cytoscape v3.10 or later.

  • all_graphics_details (bool) – True results in image with highest detail; False allows faster image generation. The default is True. Valid for bitmap formats such as PNG and JPEG. Available for Cytoscape v3.10 or later.

  • hide_labels (bool) – True makes node and edge labels invisible in image. False allows them to be drawn. The default is False. Valid for all image formats. Available for Cytoscape v3.10 or later.

  • transparent_background (bool) – True causes background to be transparent. The default is False. Valid only for PNG format. Available for Cytoscape v3.10 or later.

  • export_text_as_font (bool) – True causes text to be exported as fonts. The default is True. Valid for PDF, PS and SVG formats. Available for Cytoscape v3.10 or later.

  • orientation (str) – ‘Portrait’ allows more height for drawing space, and ‘Landscape’ allows more width. The default is ‘Portrait’. Valid for PDF format. Available for Cytoscape v3.10 or later.

  • page_size (str) – Chooses standard page size (i.e., ‘Letter’, ‘Auto’, ‘Legal’, ‘Tabloid’, ‘A0’, ‘A1’, ‘A2’, ‘A3’, ‘A4’, or ‘A5’). The default is ‘Letter’. Valid for PDF format. Available for Cytoscape v3.10 or later.

Note

This function starts with the assumption of using export functions available in Cytoscape v3.10 or later, and accepts parameters pertinent to those functions (i.e., all_graphics_details, hide_labels, transparent_background, export_text_as_font, orientation, page_size and zoom). If the caller supplies parameters appropriate for pre-3.10 Cytoscape (i.e., resolution, units, height, width and zoom) the pre-v3.10 functions will be used instead. If your Cytoscape is pre-v3.10, the pre-v3.10 functions will be called, and using v3.10 parameters will cause an exception. If your Cytoscape is v3.10 or later, passing no parameters or just the zoom parameter will result in the v3.10 functions will be called, but you can force the pre-v3.10 functions to be used by specifying force_pre_3_10 as True. Mixing pre-v3.10 and v3.10 parameters will cause an exception.

Returns

{‘file’: name of file} contains absolute path to file that was written

Return type

dict

Raises
  • CyError – if network or view doesn’t exist, or if file exists and user opts to not overwrite it, or attempting to use v3.10 parameters with a pre-v3.10 Cytoscape, or mixing v3.10 and pre-v3.10 parameters

  • requests.exceptions.RequestException – if can’t connect to Cytoscape or Cytoscape returns an error

Examples

>>> export_image('output/test', type='PDF', orientation='Landscape', hide_labels=True)
{'file': 'C:\Users\CyDeveloper\tests\output\test.pdf'}
>>> export_image('output/test', type='JPEG', all_graphics_details=False, zoom=200)
{'file': 'C:\Users\CyDeveloper\tests\output\test.jpeg'}
>>> export_image('output/test', type='JPG', hide_labels=True, zoom=200)
{'file': 'C:\Users\CyDeveloper\tests\output\test.jpg'}
>>> export_image('output/test', zoom=200, transparent_background=True)
{'file': 'C:\Users\CyDeveloper\tests\output\test.png'}
>>> export_image('output/test', force_pre_3_10=True) # use pre-v3.10 PNG renderer
{'file': 'C:\Users\CyDeveloper\tests\output\test.png'}
>>> export_image('output/test', type='PDF', overwrite_file=True) # overwrite any existing test.pdf
{'file': 'C:\Users\CyDeveloper\tests\output\test.pdf'}
>>> export_image('output/test', type='SVG', network='My Network')
{'file': 'C:\Users\CyDeveloper\tests\output\test.svg'}
>>> export_image('output/test', type='jpeg (*.jpeg, *.jpg)', network=13098)
{'file': 'C:\Users\CyDeveloper\tests\output\test.jpg'}