Wrapper for Graphics Files#

This module is deprecated.

class sage.structure.graphics_file.GraphicsFile(filename, mime_type=None)#

Bases: SageObject

Wrapper around a graphics file.


Return a byte string containing the image file.


Launch external viewer for the graphics file.


Does not actually launch a new process when doctesting.


sage: from sage.structure.graphics_file import GraphicsFile
sage: g = GraphicsFile('/tmp/test.png', 'image/png')
sage: g.launch_viewer()

Make the file available under a new filename.


  • filename – string. The new filename.

The newly-created filename will be a hardlink if possible. If not, an independent copy is created.

class sage.structure.graphics_file.Mime#

Bases: object

HTML = 'text/html'#
JAVASCRIPT = 'application/javascript'#
JMOL = 'application/jmol'#
JPG = 'image/jpeg'#
JSON = 'application/json'#
LATEX = 'text/latex'#
PDF = 'application/pdf'#
PNG = 'image/png'#
SVG = 'image/svg+xml'#
TEXT = 'text/plain'#
classmethod extension(mime_type)#

Return file extension.


  • mime_type – mime type as string.


String containing the usual file extension for that type of file. Excludes os.extsep.


sage: from sage.structure.graphics_file import Mime
sage: Mime.extension('image/png')
classmethod validate(value)#

Check that input is known mime type


  • value – string.


Unicode string of that mime type. A ValueError is raised if input is incorrect / unknown.


sage: from sage.structure.graphics_file import Mime
DeprecationWarning: the module sage.structure.graphics_file is deprecated
See https://github.com/sagemath/sage/issues/32988 for details.
sage: Mime.validate('image/png')
sage: Mime.validate('foo/bar')
Traceback (most recent call last):
ValueError: unknown mime type
sage.structure.graphics_file.graphics_from_save(save_function, preferred_mime_types, allowed_mime_types=None, figsize=None, dpi=None)#

Helper function to construct a graphics file.


  • save_function – callable that can save graphics to a file and accepts options like sage.plot.graphics.Graphics.save().

  • preferred_mime_types – list of mime types. The graphics output mime types in order of preference (i.e. best quality to worst).

  • allowed_mime_types – set of mime types (as strings). The graphics types that we can display. Output, if any, will be one of those.

  • figsize – pair of integers (optional). The desired graphics size in pixels. Suggested, but need not be respected by the output.

  • dpi – integer (optional). The desired resolution in dots per inch. Suggested, but need not be respected by the output.


Return an instance of sage.structure.graphics_file.GraphicsFile encapsulating a suitable image file. Image is one of the preferred_mime_types. If allowed_mime_types is specified, the resulting file format matches one of these.

Alternatively, this function can return None to indicate that textual representation is preferable and/or no graphics with the desired mime type can be generated.