Security News
pnpm 10.0.0 Blocks Lifecycle Scripts by Default
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
@creately/canvg
Advanced tools
In an attempt to keep this repo more active and merge PRs and do releases, if you would like to be a contributor, please start a conversation with me at gabelerner at gmail. The prerequisite is to have a few PRs open to prove out an understanding of the code. Thanks!
canvg is a SVG parser and renderer. It takes a URL to a SVG file or the text of an SVG file, parses it in JavaScript, and renders the result on a Canvas element. The rendering speed of the examples is about as fast as native SVG.
The end goal is everything from the SVG spec. The majority of the rendering and animation is working. If you would like to see a feature implemented, don't hesitate to contact me or add it to the issues list.
Locally, you can run npm start
and view the examples at http://localhost:3123/examples/index.htm
npm run build
then look in the dist
folder
npm run test-node
runs tests on node
npm run test-browser
runs tests on browser
npm run generate-expected foo.svg
to create the expected png for a given svg in the svgs
foldernpm install canvg canvas@^2 jsdom@^13 xmldom@^0
The dependencies required on the server only are peers so must be installed alongside the canvg package.
Older version
npm install canvg@^1.5
For browser applications with a build process, canvg can be installed using npm
similar to use on the server. Note in this case the peer dependencies are not required so do not need to be installed.
Alternatively, canvg can be included directly into a webpage:
<!-- Required to convert named colors to RGB -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/canvg/1.4/rgbcolor.min.js"></script>
<!-- Optional if you want blur -->
<script src="https://cdn.jsdelivr.net/npm/stackblur-canvas@^1/dist/stackblur.min.js"></script>
<!-- Main canvg code -->
<script src="https://cdn.jsdelivr.net/npm/canvg/dist/browser/canvg.min.js"></script>
Put a canvas on your page
<canvas id="canvas" width="1000px" height="600px"></canvas>
Example canvg calls:
<script>
window.onload = function() {
//load '../path/to/your.svg' in the canvas with id = 'canvas'
canvg('canvas', '../path/to/your.svg')
//load a svg snippet in the canvas with id = 'drawingArea'
canvg(document.getElementById('drawingArea'), '<svg>...</svg>')
//ignore mouse events and animation
canvg('canvas', 'file.svg', { ignoreMouse: true, ignoreAnimation: true })
}
</script>
The third parameter is options:
You can call canvg without parameters to replace all svg images on a page. See the example.
There is also a built in extension method to the canvas context to draw svgs similar to the way drawImage works:
var c = document.getElementById('canvas');
var ctx = c.getContext('2d');
ctx.drawSvg(SVG_XML_OR_PATH_TO_SVG, dx, dy, dw, dh);
FAQs
Javascript SVG parser and renderer on Canvas
The npm package @creately/canvg receives a total of 3 weekly downloads. As such, @creately/canvg popularity was classified as not popular.
We found that @creately/canvg demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 7 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.