Skip to content

stela5/svg2json

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 

Repository files navigation

svg2json

svg2json is a PHP library for converting SVG to JSON format and was largely inspired by Aaron Lindsay's SVG to dojox.gfx Convertor. The JSON format is agnostic but works best with dojox.gfx (e.g. inspector demo).

WARNING: This code is alpha quality and is not meant for general production use. For example, most SVG tests fail or produce partial results. See Q&A below for other SVG/Canvas libraries that are more robust or stable. Otherwise, feel free to fork and improve this code!

Requirements

  1. A web server with PHP enabled (tested on version 5.3.6 but other versions may work)

  2. PhantomJS (used for complex bounding box calculations)

  3. optional Dojox.gfx Plugins (for blur and shadow effects)

Usage

See demo.htm and test.htm in the src directory.

FAQ

Q: Why convert SVG to JSON?
A: The JSON format is more compact and can be used in conjunction with various JavaScript libraries to display SVG content on older versions of IE and other platforms that only support Canvas.

Q: Why do I get errors when converting a specific SVG file?
A: Most likely because:

  • The SVG file uses advanced filters (only blur and shadow are currently supported)
  • The SVG file uses non-standard effects or non-standard attributes/elements
  • The SVG file does not use the SVG 1.1 Second Edition standard
  • The SVG file is corrupt (open in Squiggle or another SVG-compliant browser to verify)
  • Your chosen JSON renderer encountered a bug (for example, Dojox.GFX does not currently support applying a transform to a gradient)
  • svg2json encountered a bug (please report here or fork)

Q: Why is it so slow? Why is the code so ugly? Are we there yet? ...etc.
A: This project is experimental. If speed, performance, and robustness are your top priority, consider using Batik, Ample SDK, FabricJS, or Ready Set Raphael. Also, feel free to fork this code and improve it!

Dual-Licensed

Copyright (c) 2011, Stela 5

About

Convert SVG to JSON

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages