cutcutcodec.core.io.read_svg

Decode the svg vectorial images based on cairosvg lib.

Classes

ContainerInputSVG(filename, *[, unsafe])

Decode an svg image to a matricial image of any dimension.

Details

class cutcutcodec.core.io.read_svg.ContainerInputSVG(filename: str | bytes | Path, *, unsafe=False)[source]

Decode an svg image to a matricial image of any dimension.

Attributes

filenamepathlib.Path

The path to the physical file that contains the svg data (readonly).

Examples

>>> from cutcutcodec.core.io.read_svg import ContainerInputSVG
>>> from cutcutcodec.utils import get_project_root
>>> (stream,) = ContainerInputSVG(get_project_root() / "examples" / "logo.svg").out_streams
>>> stream.snapshot(0, (9, 9))[..., 3]
tensor([[0.0000, 0.0627, 0.5529, 0.8275, 0.9608, 0.8275, 0.5529, 0.0627, 0.0000],
        [0.0745, 0.8471, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 0.8471, 0.0745],
        [0.5686, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 0.5647],
        [0.8863, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 0.8824],
        [0.9765, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 0.9765],
        [0.8863, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 0.8824],
        [0.5686, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 0.5647],
        [0.0745, 0.8471, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 0.8471, 0.0745],
        [0.0000, 0.0627, 0.5529, 0.8275, 0.9608, 0.8275, 0.5529, 0.0627, 0.0000]])
>>>

Initialise and create the class.

Parameters

filenamepathlike

Path to the file to be decoded.

unsafebool

Transmitted to cairosvg.svg2png.

Raises

cutcutcodec.core.exceptions.DecodeError

If it fail to extract any multimedia stream from the provided file.