My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for

Convert a SVG file to a canvas script.

Usage

java -jar svg2canvas.jar [options] (stdin| <svg files> )

Requirement

java 6

Download

svg2canvas.jar in http://code.google.com/p/lindenb/downloads/list

options

  • -o (fileout)
  • -p (integer) precision default:2
  • -help (this screen)

Example

java -jar svg2canvas.jar  ~/file.svg 

<html><body>
<div>
<canvas id='ctx1258901170932' width='744.09448819' height='1052.3622047'></canvas>
<script>
function paint1258901170932(){var canvas=document.getElementById('ctx12589011709
32');if (!canvas.getContext) return;var c=canvas.getContext('2d');
c.fillStyle="white";
c.strokeStyle="black";
c.globalAlpha="1.0";
c.lineWidth="1";
c.lineCap="butt";
c.lineJoin="round";
c.mitterLimit="1";
c.textAnchor="start";
c.font="normal normal 12 Courier";
c.fillStyle="#000203";
c.globalAlpha="0.81327801";
c.lineWidth="11.39999961999999911";
c.lineCap="round";
c.mitterLimit="4";
c.beginPath();
c.moveTo(250.52,330.10);
c.bezierCurveTo(249.81,333.11,252.96,338.22,254.56,342.22);
c.bezierCurveTo(255.64,344.94,257.87,348.49,259.61,350.81);
c.bezierCurveTo(261.07,352.76,260.11,358.44,260.11,360.91);
c.bezierCurveTo(260.11,363.90,260.41,366.64,261.12,369.50);
c.bezierCurveTo(261.91,372.65,264.32,374.38,265.67,377.08);
(...)
Comment by emrahatilkan, Feb 8, 2010

so can html 5 canvas don't that by itself, i will stick with flash...

Comment by smwe...@gmail.com, Feb 28, 2010

Would you consider releasing the source code? I'd like to modify this to return a function that takes a canvas context as a parameter 'c' and returns separate functions for each path. Already I can do this with regular expression but it'd be more efficient to have java run it rather than a separate process.

Comment by project member plindenb...@gmail.com, May 18, 2010

@smweiss the source code is available at http://code.google.com/p/lindenb/source/browse/ search for SVGToCanvas

Comment by enzer...@gmail.com, Jul 3, 2010

Can You maybe Update it To Support Gradient. I See All My Gradient Linear and Redial Are White After Output ?

Comment by TeuF...@gmail.com, Jul 20, 2010

I think I am in love with this converter!

Comment by Anna.Shi...@gmail.com, Dec 20, 2010

In my system the converter seems to use comma instead of point as a decimal separator (Mac OS X 10.6.5, Russian localization).

Comment by move.4...@gmail.com, Sep 15, 2011

brilliant. thanks for this, ive been looking for something like this for a while now.

you sir, are the man.


Sign in to add a comment
Powered by Google Project Hosting