Nocairosvg Index / Nocairosvg
Auto-generated documentation for nocairosvg module.
Convert a colour string to tuple.
colour
Optional[str] - the colour
Tuple[int, int, int, int]: the converted colour
def colour2tuple(colour: str | None) -> tuple[int, int, int, int]: ...
Launch playwright and use the html canvas to convert.
url
str - location of the image to convert background_colour (Tuple[int, int, int, int], optional): Set the background colour. Defaults to (0, 0, 0, 0). size (Tuple[Optional[int], Optional[int]], optional): Size to crop the image to. Defaults to (None, None).
Image.Image
- PIL Image
def convert(
url: str,
background_colour: tuple[int, int, int, int] = (0, 0, 0, 0),
size: tuple[int | None, int | None] = (None, None),
) -> Image.Image: ...
Get a file url from a bytestring, file object, or url...
bytestring
Optional[bytes], optional - svg bytes. Defaults to None.file_obj
Optional[FileIO], optional - file object. Defaults to None.url
Optional[str], optional - path. Defaults to None.
str
- path
def resolve_file_url(
bytestring: bytes | None = None,
file_obj: FileIO | None = None,
url: str | None = None,
) -> str: ...
Convert an SVG to an SVG.
bytestring
Optional[bytes], optional - bytes containing svg data. Defaults to None.file_obj
Optional[FileIO], optional - opened file object. Defaults to None.url
Optional[str], optional - path to file. Defaults to None.dpi
int, optional - dpi. Defaults to 96.parent_width
Optional[int], optional - width of the parent element (e.g. div). Defaults to None.parent_height
Optional[int], optional - height of the parent element (e.g. div). Defaults to None.scale
float, optional - scale the image by . Defaults to 1.background_color
Optional[str], optional - Set a bg colour if not transparent. Defaults to None.negate_colors
bool, optional - invert the image colours. Defaults to False.invert_images
bool, optional - invert the image colours. Defaults to False. write_to (Union[str, FileIO, None], optional): file path/ object to write to (Omit to return bytes). Defaults to None.output_width
Optional[int], optional - width of output image. Defaults to None.output_height
Optional[int], optional - height of output image. Defaults to None.ext
str - image type. Defaults to 'png'transparent
bool - Should the image be transparent. Defaults to True
Optional[bytes]
- Bytes of image if write_to is None. else writes image to file
def svg2bitmap(
bytestring: bytes | None = None,
file_obj: FileIO | None = None,
url: str | None = None,
dpi: int = 96,
parent_width: int | None = None,
parent_height: int | None = None,
scale: float = 1,
background_color: str | None = None,
negate_colors: bool = False,
invert_images: bool = False,
write_to: str | FileIO | None = None,
output_width: int | None = None,
output_height: int | None = None,
ext: str = "png",
transparent: bool = True,
) -> bytes | None: ...
Convert an SVG to EPS.
bytestring
Optional[bytes], optional - bytes containing svg data. Defaults to None.file_obj
Optional[FileIO], optional - opened file object. Defaults to None.url
Optional[str], optional - path to file. Defaults to None.dpi
int, optional - dpi. Defaults to 96.parent_width
Optional[int], optional - width of the parent element (e.g. div). Defaults to None.parent_height
Optional[int], optional - height of the parent element (e.g. div). Defaults to None.scale
float, optional - scale the image by . Defaults to 1.unsafe
bool, optional - NA here . Defaults to False.background_color
Optional[str], optional - Set a bg colour if not transparent. Defaults to None.negate_colors
bool, optional - invert the image colours. Defaults to False.invert_images
bool, optional - invert the image colours. Defaults to False. write_to (Union[str, FileIO, None], optional): file path/ object to write to (Omit to return bytes). Defaults to None.output_width
Optional[int], optional - width of output image. Defaults to None.output_height
Optional[int], optional - height of output image. Defaults to None.
Optional[bytes]
- Bytes of image if write_to is None. else writes image to file
def svg2eps(
bytestring: bytes | None = None,
file_obj: FileIO | None = None,
url: str | None = None,
dpi: int = 96,
parent_width: int | None = None,
parent_height: int | None = None,
scale: float = 1,
unsafe: bool = False,
background_color: str | None = None,
negate_colors: bool = False,
invert_images: bool = False,
write_to: str | FileIO | None = None,
output_width: int | None = None,
output_height: int | None = None,
) -> bytes | None: ...
Convert an SVG to a PDF.
bytestring
Optional[bytes], optional - bytes containing svg data. Defaults to None.file_obj
Optional[FileIO], optional - opened file object. Defaults to None.url
Optional[str], optional - path to file. Defaults to None.dpi
int, optional - dpi. Defaults to 96.parent_width
Optional[int], optional - width of the parent element (e.g. div). Defaults to None.parent_height
Optional[int], optional - height of the parent element (e.g. div). Defaults to None.scale
float, optional - scale the image by . Defaults to 1.unsafe
bool, optional - NA here . Defaults to False.background_color
Optional[str], optional - Set a bg colour if not transparent. Defaults to None.negate_colors
bool, optional - invert the image colours. Defaults to False.invert_images
bool, optional - invert the image colours. Defaults to False. write_to (Union[str, FileIO, None], optional): file path/ object to write to (Omit to return bytes). Defaults to None.output_width
Optional[int], optional - width of output image. Defaults to None.output_height
Optional[int], optional - height of output image. Defaults to None.
Optional[bytes]
- Bytes of image if write_to is None. else writes image to file
def svg2pdf(
bytestring: bytes | None = None,
file_obj: FileIO | None = None,
url: str | None = None,
dpi: int = 96,
parent_width: int | None = None,
parent_height: int | None = None,
scale: float = 1,
unsafe: bool = False,
background_color: str | None = None,
negate_colors: bool = False,
invert_images: bool = False,
write_to: str | FileIO | None = None,
output_width: int | None = None,
output_height: int | None = None,
) -> bytes | None: ...
Convert an SVG to a PNG.
bytestring
Optional[bytes], optional - bytes containing svg data. Defaults to None.file_obj
Optional[FileIO], optional - opened file object. Defaults to None.url
Optional[str], optional - path to file. Defaults to None.dpi
int, optional - dpi. Defaults to 96.parent_width
Optional[int], optional - width of the parent element (e.g. div). Defaults to None.parent_height
Optional[int], optional - height of the parent element (e.g. div). Defaults to None.scale
float, optional - scale the image by . Defaults to 1.unsafe
bool, optional - NA here . Defaults to False.background_color
Optional[str], optional - Set a bg colour if not transparent. Defaults to None.negate_colors
bool, optional - invert the image colours. Defaults to False.invert_images
bool, optional - invert the image colours. Defaults to False. write_to (Union[str, FileIO, None], optional): file path/ object to write to (Omit to return bytes). Defaults to None.output_width
Optional[int], optional - width of output image. Defaults to None.output_height
Optional[int], optional - height of output image. Defaults to None.
Optional[bytes]
- Bytes of image if write_to is None. else writes image to file
def svg2png(
bytestring: bytes | None = None,
file_obj: FileIO | None = None,
url: str | None = None,
dpi: int = 96,
parent_width: int | None = None,
parent_height: int | None = None,
scale: float = 1,
unsafe: bool = False,
background_color: str | None = None,
negate_colors: bool = False,
invert_images: bool = False,
write_to: str | FileIO | None = None,
output_width: int | None = None,
output_height: int | None = None,
) -> bytes | None: ...
Convert an SVG to PS.
bytestring
Optional[bytes], optional - bytes containing svg data. Defaults to None.file_obj
Optional[FileIO], optional - opened file object. Defaults to None.url
Optional[str], optional - path to file. Defaults to None.dpi
int, optional - dpi. Defaults to 96.parent_width
Optional[int], optional - width of the parent element (e.g. div). Defaults to None.parent_height
Optional[int], optional - height of the parent element (e.g. div). Defaults to None.scale
float, optional - scale the image by . Defaults to 1.unsafe
bool, optional - NA here . Defaults to False.background_color
Optional[str], optional - Set a bg colour if not transparent. Defaults to None.negate_colors
bool, optional - invert the image colours. Defaults to False.invert_images
bool, optional - invert the image colours. Defaults to False. write_to (Union[str, FileIO, None], optional): file path/ object to write to (Omit to return bytes). Defaults to None.output_width
Optional[int], optional - width of output image. Defaults to None.output_height
Optional[int], optional - height of output image. Defaults to None.
Optional[bytes]
- Bytes of image if write_to is None. else writes image to file
def svg2ps(
bytestring: bytes | None = None,
file_obj: FileIO | None = None,
url: str | None = None,
dpi: int = 96,
parent_width: int | None = None,
parent_height: int | None = None,
scale: float = 1,
unsafe: bool = False,
background_color: str | None = None,
negate_colors: bool = False,
invert_images: bool = False,
write_to: str | FileIO | None = None,
output_width: int | None = None,
output_height: int | None = None,
) -> bytes | None: ...
Convert an SVG to an SVG.
bytestring
Optional[bytes], optional - bytes containing svg data. Defaults to None.file_obj
Optional[FileIO], optional - opened file object. Defaults to None.url
Optional[str], optional - path to file. Defaults to None.dpi
int, optional - dpi. Defaults to 96.parent_width
Optional[int], optional - width of the parent element (e.g. div). Defaults to None.parent_height
Optional[int], optional - height of the parent element (e.g. div). Defaults to None.scale
float, optional - scale the image by . Defaults to 1.unsafe
bool, optional - NA here . Defaults to False.background_color
Optional[str], optional - Set a bg colour if not transparent. Defaults to None.negate_colors
bool, optional - invert the image colours. Defaults to False.invert_images
bool, optional - invert the image colours. Defaults to False. write_to (Union[str, FileIO, None], optional): file path/ object to write to (Omit to return bytes). Defaults to None.output_width
Optional[int], optional - width of output image. Defaults to None.output_height
Optional[int], optional - height of output image. Defaults to None.
Optional[bytes]
- Bytes of image if write_to is None. else writes image to file
def svg2svg(
bytestring: bytes | None = None,
file_obj: FileIO | None = None,
url: str | None = None,
dpi: int = 96,
parent_width: int | None = None,
parent_height: int | None = None,
scale: float = 1,
unsafe: bool = False,
background_color: str | None = None,
negate_colors: bool = False,
invert_images: bool = False,
write_to: str | FileIO | None = None,
output_width: int | None = None,
output_height: int | None = None,
) -> bytes | None: ...
Write the pil image to the filesystem.
image
Image.Image - pillow image file (Union[str, FileIO, None]): the fileext
str - the image extensiondpi
int - the dpi
Optional[bytes]
- the image data in bytes if no file specified
def write(
image: Image.Image, file: str | FileIO | None, ext: str, dpi: int
) -> bytes | None: ...