ImageScript v4.0.0
    Preparing search index...

    InterfaceSVGResourceOptions

    The limits, fonts and images of Image.renderSVG, part of RenderSVGOptions

    interface SVGResourceOptions {
        font?: BinaryData | BinaryData[];
        images?: Record<string, BinaryData | Image>;
        maxImagePixels?: number;
        maxLayerPixels?: number;
        maxPixels?: number;
    }
    Index

    Fonts for <text> (TrueType, OpenType or WOFF; not WOFF2 or some newer OpenType outline formats such as CFF2): each text gets the face its font-family, font-weight, font-style and font-stretch match best among them, by the names, weights and styles in the fonts (like browsers match installed fonts). Generic families (serif, sans-serif, monospace, ...) are the first font that fits them, other families and text without one get the first font's family; characters a face doesn't have come from the other fonts (TrueType, OpenType or WOFF). Fonts the SVG embeds with @font-face (in data: URIs) are used too, before these for their family names. Without any fonts text isn't rendered (an empty array is the same as no option here; Image.renderText needs a font and throws for it). One font can be given without an array. A font here that can't be read throws an Error, like in Image.renderText; a damaged font that the SVG embeds is left out

    []

    images?: Record<string, BinaryData | Image>

    Images for the <image> elements (and feImage) by their href, the same string the SVG uses: with images: { 'logo.png': bytes }, <image href="logo.png" .../> draws the image. Values are encoded images (PNG, JPEG, WebP, GIF's first frame, ...) or Images, decoded like data URI images are, and only for the hrefs the SVG references. Nothing else is read: no files and no URLs, so drawing an image whose href isn't given (and isn't a data URI) throws, as does drawing one that can't be decoded. SVG documents can't be given this way, use a data URI for them

    {}

    maxImagePixels?: number

    Maximum total pixels of the raster images the SVG references (data URIs and SVGResourceOptions.images), decoded together; already-decoded Image values are used as supplied and don't count. Drawing an image beyond the limit throws a LimitError (a RangeError)

    maxPixels; Infinity disables the limit

    maxLayerPixels?: number

    Maximum pixels of the layers rendering uses at once, the output's included. Groups with opacity, masks, clip paths of nested viewports, filters and blend modes are each rendered into a layer of their own (up to the output's size, 16 bytes per pixel) while their content is drawn, so deeply nested ones multiply the memory a small SVG takes. Exceeding it throws a LimitError (a RangeError). With the defaults, rendering can take about 90 bytes per pixel of maxPixels (64 for the layers, up to 20 for the images, 4 for the output): lower maxPixels to bound it for untrusted SVGs.

    Three limits on the work of a render don't depend on these options, and grow with the size of the output (so lowering maxPixels is what bounds them too). Each throws a LimitError when exceeded:

    • Painting: shapes and layers may paint 2²⁸ pixels plus 64 per pixel of the output
    • Paths: all paths together may be made of 2²⁵ points plus 4 per pixel of the output (curves flattened, each copy drawn through <use> counted, a command of a glyph outline 16), one path of 2²¹ (texts excepted)
    • Filters: all the filters' primitives together may work on 2²⁵ pixels plus 16 per pixel of the output (a primitive counts its region's pixels once per pass: an feConvolveMatrix per 9 taps of its kernel, an feTurbulence per octave, an feMerge per node)

    4 * maxPixels; Infinity disables the limit

    maxPixels?: number

    Maximum total pixels in the rendered output. Output over the limit throws a LimitError (a RangeError) before anything is rendered. It's also the default of SVGResourceOptions.maxLayerPixels and SVGResourceOptions.maxImagePixels. The work limits of rendering grow with it: see SVGResourceOptions.maxLayerPixels

    268402689 (16383²); Infinity disables the limit