scistag.imagestag.svg.SvgRenderer¶
- class SvgRenderer[source]¶
Bases:
objectSVG rendering class which renders an SVG using the Cairo SVG library.
Important: This class requires Cairo being installed on your system. For Linux and OS X users this is usually a one-liner, see https://www.cairographics.org/download/.
All standard SciStag Docker images already contain the pre-installed Cairo SVG and other base tools, so there is nothing for you to do. (https://hub.docker.com/r/scistag)
If you are a Windows user: It is in general possible to build Cairo for Windows too but after days of recherche and just stumbling over often more than 10+ years outdated last updates on the official sites I decided that this is not a “clean” solution. In consequence I converted all essential SVGs tof pre-rendered PNGs - such as basic UI graphics, emojis, country flags etc. - to the module so that SVG rendering is not required in general for using 98% of the functions of SciStag.
To suppress this message call scistag.imagestag.SvgRenderer.set_verbose() at the beginning of your script. Alternatively you can set the SCISTAG_SUPPORT_SVG environment variable to 0.
If you do need hi-quality live rendered SVGs in your application we recommend using Docker for Windows and using one of our provided Docker images available on https://hub.docker.com/r/scistag.
If you do not want to dockerize your application then running and debugging your application via WSL2 is also workaround, see https://thecodeblogger.com/2020/09/24/wsl-setup-vs-code-for-python-development/ or https://www.jetbrains.com/help/pycharm/using-wsl-as-a-remote-interpreter.html
To keep track of the status see https://github.com/SciStag/SciStag/issues/2
Usage:
` py from scistag.imagestack import SvgRenderer my_svg = open("example.svg").read() image = SvgRenderer.render(my_svg) `Methods
Returns if SVG rendering is available :rtype:
bool:return: True if it isRenders an SVG
Defines if warnings about Cairo not being available shall be suppressed
Attributes
__dict____doc____module____weakref__list of weak references to the object (if defined)
_access_lock_cairo_available_initialized_svg_to_png_verbose- classmethod available()[source]¶
Returns if SVG rendering is available :rtype:
bool:return: True if it is
- classmethod render(svg_data, output_width=None, output_height=None, bg_color=None)[source]¶
Renders an SVG
- Parameters
svg_data (bytes) – The SVG’s data
output_width – The desired output with. Optional.
output_height – The desired output height. Optional.
bg_color (ColorTypes | None) – If specified the background will be filled with this color
- Return type
Image | None
- Returns
The image if the rendering was successful. None otherwise.