imageReadSvg

Reads an SVG and rasterises it into an ordinary CFML image object, so the whole image* family (resize, crop, draw on, imageWrite to png/jpg/gif) applies to it. source is either a path to an .svg file or the SVG markup itself (strings containing

imageReadSvg(source [, width [, height]]) → returns any

This function requires RustCFML.  Not supported on Lucee, Adobe ColdFusion, etc.

Argument Reference

source string
Required

Path to an .svg file, or the SVG markup itself.

width numeric

Optional target width in pixels; the height is derived from the aspect ratio when only one dimension is given.

height numeric

Optional target height in pixels; when both dimensions are given the SVG is scaled to fit inside the box.

Compatibility

RustCFML:

Not supported on wasm32.

Examples
Sample code invoking the imageReadSvg function

Read an SVG at native size and write it as a PNG.

img = imageReadSvg(expandPath("/logo.svg"));
imageWrite(img, expandPath("/logo.png"));

Rasterise inline SVG markup into a 200x100 box.

svg = "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"400\" height=\"200\"><rect width=\"400\" height=\"200\" fill=\"red\"/></svg>";
img = imageReadSvg(svg, 200, 100);
writeDump(imageInfo(img));

Signup for cfbreak to stay updated on the latest news from the ColdFusion / CFML community. One email, every friday.

Fork me on GitHub