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.
- data()#
Return a byte string containing the image file.
- filename()#
- launch_viewer()#
Launch external viewer for the graphics file.
Note
Does not actually launch a new process when doctesting.
EXAMPLES:
sage: from sage.structure.graphics_file import GraphicsFile sage: g = GraphicsFile('/tmp/test.png', 'image/png') sage: g.launch_viewer()
- mime()#
- save_as(filename)#
Make the file available under a new filename.
INPUT:
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.
INPUT:
mime_type
– mime type as string.
OUTPUT:
String containing the usual file extension for that type of file. Excludes
os.extsep
.EXAMPLES:
sage: from sage.structure.graphics_file import Mime sage: Mime.extension('image/png') 'png'
- classmethod validate(value)#
Check that input is known mime type
INPUT:
value
– string.
OUTPUT:
Unicode string of that mime type. A
ValueError
is raised if input is incorrect / unknown.EXAMPLES:
sage: from sage.structure.graphics_file import Mime doctest:warning... DeprecationWarning: the module sage.structure.graphics_file is deprecated See https://trac.sagemath.org/32988 for details. sage: Mime.validate('image/png') '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.
INPUT:
save_function
– callable that can save graphics to a file and accepts options likesage.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.
OUTPUT:
Return an instance of
sage.structure.graphics_file.GraphicsFile
encapsulating a suitable image file. Image is one of thepreferred_mime_types
. Ifallowed_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.