$44 GRAYBYTE WORDPRESS FILE MANAGER $83

SERVER : premium201.web-hosting.com #1 SMP Wed Mar 26 12:08:09 UTC 2025
SERVER IP : 172.67.162.162 | ADMIN IP 216.73.216.51
OPTIONS : CRL = ON | WGT = ON | SDO = OFF | PKEX = OFF
DEACTIVATED : NONE

/opt/cloudlinux/venv/lib/python3.11/site-packages/lvestats/lib/chart/

HOME
Current File : /opt/cloudlinux/venv/lib/python3.11/site-packages/lvestats/lib/chart//svg2png.py
# coding=utf-8
#
# Copyright © Cloud Linux GmbH & Cloud Linux Software, Inc 2010-2025 All Rights Reserved
#
# Licensed under CLOUD LINUX LICENSE AGREEMENT
# http://cloudlinux.com/docs/LICENSE.TXT
import os
import subprocess
from typing import Optional


def svg_to_png(svg_data: str) -> bytes:
    """
    Converts SVG data to PNG format using available converters.

    Args:
        svg_data (str): The SVG data to convert.

    Returns:
        bytes: The converted PNG data.

    Raises:
        RuntimeError: If no suitable converter is found.
    """
    # alt-ImageMagick is preferred over the native ImageMagick and rsvg.
    alt_imagemagick = _get_alt_imagemagick_binary()
    if alt_imagemagick:
        return _convert_with_imagemagick(svg_data, alt_imagemagick)

    rsvg_convert = _get_rsvg_convert_binary()
    if rsvg_convert:
        return _convert_with_rsvg(svg_data, rsvg_convert)

    imagemagick = _get_imagemagick_binary()
    if imagemagick:
        return _convert_with_imagemagick(svg_data, imagemagick)

    raise RuntimeError("No suitable SVG to PNG converter found")


def _get_alt_imagemagick_binary() -> Optional[str]:
    """
    Returns the path to the alt-ImageMagick binary if it exists, otherwise None.
    """
    alt_imagemagick = "/opt/alt/alt-ImageMagick/usr/bin/magick"
    if os.path.exists(alt_imagemagick):
        return alt_imagemagick
    return None


def _get_imagemagick_binary() -> Optional[str]:
    """
    Returns the path to the ImageMagick binary if it exists, otherwise None.
    """
    native_imagemagick = "/usr/bin/convert"
    if os.path.exists(native_imagemagick):
        return native_imagemagick
    return None


def _get_rsvg_convert_binary() -> Optional[str]:
    """
    Returns the path to the rsvg-convert binary if it exists, otherwise None.
    """
    rsvg_convert = "/usr/bin/rsvg-convert"
    if os.path.exists(rsvg_convert):
        return rsvg_convert
    return None


def _convert_with_rsvg(svg_data: str, rsvg_convert: str) -> bytes:
    """
    Converts SVG data to PNG format using rsvg-convert.

    Args:
        svg_data (str): The SVG data to convert.
        rsvg_convert (str): The path to the rsvg-convert binary.

    Returns:
        bytes: The converted PNG data.
    """
    cwd = '/var/lve/tmp' if os.getuid() == 0 else None
    with subprocess.Popen(
        [rsvg_convert, "-f", "png", "-b", "rgba(255, 255, 255, 255)"],
        stdin=subprocess.PIPE,
        stdout=subprocess.PIPE,
        cwd=cwd
    ) as proc:
        png_data, _ = proc.communicate(input=svg_data.encode())
    return png_data


def _convert_with_imagemagick(svg_data: str, imagemagick: str) -> bytes:
    """
    Converts SVG data to PNG format using ImageMagick.

    Args:
        svg_data (str): The SVG data to convert.
        imagemagick (str): The path to the ImageMagick binary.

    Returns:
        bytes: The converted PNG data.
    """
    cwd = '/var/lve/tmp' if os.getuid() == 0 else None
    with subprocess.Popen(
        [imagemagick, "-", "png:-"],
        stdin=subprocess.PIPE,
        stdout=subprocess.PIPE,
        cwd=cwd
    ) as proc:
        png_data, _ = proc.communicate(input=svg_data.encode())
    return png_data

Current_dir [ NOT WRITEABLE ] Document_root [ NOT WRITEABLE ]


[ Back ]
NAME
SIZE
LAST TOUCH
USER
CAN-I?
FUNCTIONS
..
--
19 May 2026 8.30 AM
root / root
0755
__pycache__
--
19 May 2026 8.30 AM
root / root
0755
__init__.py
19.8 KB
28 Apr 2026 1.04 PM
root / root
0644
dbgovchartmain.py
4.361 KB
28 Apr 2026 1.04 PM
root / root
0644
lvechartmain.py
15.412 KB
28 Apr 2026 1.04 PM
root / root
0644
polysimplify.py
7.378 KB
28 Apr 2026 1.04 PM
root / root
0644
rdp.py
1.4 KB
28 Apr 2026 1.04 PM
root / root
0644
svg2png.py
3.141 KB
28 Apr 2026 1.04 PM
root / root
0644
svggraph.py
20.729 KB
28 Apr 2026 1.04 PM
root / root
0644
util.py
0.473 KB
28 Apr 2026 1.04 PM
root / root
0644

GRAYBYTE WORDPRESS FILE MANAGER @ 2026 CONTACT ME
Static GIF Static GIF