How to use the cairosvg.SURFACES function in CairoSVG

To help you get started, we’ve selected a few CairoSVG examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Kozea / CairoSVG / test / __init__.py View on Github external
def test(format_name=format_name):
            """Test the generation of ``format_name`` images."""
            content = cairosvg.SURFACES[format_name].convert(url=svg_filename)
            assert content.startswith(MAGIC_NUMBERS[format_name])
        test.description = 'Test that the output from svg2%s looks like %s' % (
github Kozea / CairoSVG / cairosvg / test_api.py View on Github external
def test_formats(format_name):
    """Convert to a given format and test that output looks right."""
    content = SURFACES[format_name].convert(SVG_SAMPLE)
    assert content.startswith(MAGIC_NUMBERS[format_name])
github Calysto / calysto / calysto / graphics.py View on Github external
def convert(self, format="png", **kwargs):
        """
        png, ps, pdf, gif, jpg, svg
        returns image in format as bytes
        """
        if format.upper() in cairosvg.SURFACES:
            surface = cairosvg.SURFACES[format.upper()]
        else:
            raise Exception("'%s' image format unavailable: use one of %s" %
                            (format.upper(), list(cairosvg.SURFACES.keys())))
        return surface.convert(bytestring=str(self), **kwargs)
github Kozea / CairoSVG / cairosvg / __main__.py View on Github external
def main(argv=None, stdout=None, stdin=None):
    """Entry-point of the executable."""
    # Get command-line options
    parser = argparse.ArgumentParser(
        description='Convert SVG files to other formats')
    parser.add_argument('input', default='-', help='input filename or URL')
    parser.add_argument(
        '-v', '--version', action='version', version=VERSION)
    parser.add_argument(
        '-f', '--format', help='output format',
        choices=sorted([surface.lower() for surface in SURFACES]))
    parser.add_argument(
        '-d', '--dpi', default=96, type=float,
        help='ratio between 1 inch and 1 pixel')
    parser.add_argument(
        '-W', '--width', default=None, type=float,
        help='width of the parent container in pixels')
    parser.add_argument(
        '-H', '--height', default=None, type=float,
        help='height of the parent container in pixels')
    parser.add_argument(
        '-s', '--scale', default=1, type=float, help='output scaling factor')
    parser.add_argument(
        '-b', '--background', metavar='COLOR', help='output background color')
    parser.add_argument(
        '-n', '--negate-colors', action='store_true',
        help='replace every vector color with its complement')
github Calysto / calysto / calysto / graphics.py View on Github external
def convert(self, format="png", **kwargs):
        """
        png, ps, pdf, gif, jpg, svg
        returns image in format as bytes
        """
        if format.upper() in cairosvg.SURFACES:
            surface = cairosvg.SURFACES[format.upper()]
        else:
            raise Exception("'%s' image format unavailable: use one of %s" %
                            (format.upper(), list(cairosvg.SURFACES.keys())))
        return surface.convert(bytestring=str(self), **kwargs)
github Kozea / CairoSVG / cairosvg / __main__.py View on Github external
'output_width': options.output_width,
        'output_height': options.output_height}
    stdin = stdin or sys.stdin
    stdout = stdout or sys.stdout
    kwargs['write_to'] = (
        stdout.buffer if options.output == '-' else options.output)
    if options.input == '-':
        kwargs['file_obj'] = stdin.buffer
    else:
        kwargs['url'] = options.input
    output_format = (
        options.format or
        os.path.splitext(options.output)[1].lstrip('.') or
        'pdf').upper()

    SURFACES[output_format.upper()].convert(**kwargs)