Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
canvas2svg
Advanced tools
Readme
This library turns your Canvas into SVG using javascript. In other words, this library lets you build an SVG document using the canvas api. Why use it?
http://gliffy.github.io/canvas2svg/
We create a mock 2d canvas context. Use the canvas context like you would on a normal canvas. As you call methods, we build up a scene graph in SVG. Yay!
//Create a new mock canvas context. Pass in your desired width and height for your svg document.
var ctx = new C2S(500,500);
//draw your canvas like you would normally
ctx.fillStyle="red";
ctx.fillRect(100,100,100,100);
//etc...
//serialize your SVG
var mySerializedSVG = ctx.getSerializedSvg(); //true here, if you need to convert named to numbered entities.
//If you really need to you can access the shadow inline SVG created by calling:
var svg = ctx.getSvg();
To run tests:
npm install
npm test
To run tests against Chrome and Firefox, call karma directly. This is not the default npm test due to the limited browser selection in travis.
npm install karma-cli -g
karma start
Play with canvas2svg in the provided test/playground.html or run test locally in your browser in test/testrunner.html
Add a test file to the test/example folder. In your file make sure to add the drawing function to the global C2S_EXAMPLES
,
with your filename as a key. For example test\example\linewidth.js
should look something like:
window.C2S_EXAMPLES['linewidth'] = function(ctx) {
for (var i = 0; i < 10; i++){
ctx.lineWidth = 1+i;
ctx.beginPath();
ctx.moveTo(5+i*14,5);
ctx.lineTo(5+i*14,140);
ctx.stroke();
}
};
install gulp globally if you haven't done so already
npm install -g gulp
Then run the following to update playground.html and testrunner.html
gulp
You should now be able to select your new example from playground.html or see it run in testrunner.html
If you find a bug, or want to add functionality, please add a new test case and include it with your pull request.
You can use canvas2svg
with node.js using jsdom with node-canvas. To do this first create a new document object, and then create a new instance of C2S
based on that document:
var canvas = require('canvas'),
jsdom = require('jsdom'),
C2S = require('canvas2svg');
var document = jsdom.jsdom();
var ctx = new C2S({document: document});
// ... drawing code goes here ...
N.B. You may not need node-canvas for some simple operations when using jsdom >= 6.3.0, but it's still recommended that you install it.
Some canvas 2d context methods are not implemented yet. Watch out for setTransform and arcTo.
To release a new version:
gulp bump
to update the version numbergit commit -am v1.0.xx
git push
npm publish
This library is licensed under the MIT license.
FAQs
canvas2svg
The npm package canvas2svg receives a total of 1,993 weekly downloads. As such, canvas2svg popularity was classified as popular.
We found that canvas2svg demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.