Karthik wrote:
Terence wrote:
Karthik wrote:
Hi,
I am just curious if there is any existing API in PHP for rendering
SVG (Scalable Vector Graphics). A quick search in Google pointed to
me a place in zend.com -
http://www.zend.com/zend/trick/tricks12apr.php .
where I feel the support for SVG is not very clear to be exact.
Just curious if there is a library that comes with PHP that can
help us to create PHP without exactly boggling down in the SVG syntax
( XML ) as given in the above mentioned example.
Not that I know of.
Sounds like an interesting idea though. Not something that needs to be
implemented as a PHP module. Could be done with some PHP classes.
What sort of functions would you expect/desire in a "simplified " SVG API?
I was reading the specification of SVG. And I was wondering if there
is a nice abstraction of the SVG document, similar to an XML document. I
am concerned more about writing SVG files, at the moment than reading
them (which I guess could be done by the plugin anyway).
As such the SVG spec. provides ways to draw a circle , rectangle (and
much more). I was wondering if there could be a nice API that can
eventually help me write a SVG document without me knowing anything
about XML in the first place (but, of course with some knowledge of the
SVG specification).
OK, given that an SVG extension doesn't exist, I don't think it would be
too difficult to create an API that implements DOM in the internals to
generate the required SVG XML.
I'd start by creating a class for each type of primary 2d object. For
instance:
- point
- line,
- circle
etc.
I'm sure SVG has elements for all of these. Then you write a class which
represents an SVG document. Maybe it has methods like.
setDocTitle();
PlaceObject([point|line|circ le],x,y);
// returns reference to placed object
RemoveObject([reference to target object]);
GroupObjects([obj ref|array of objects],[group name]); // returns group
ConsumeObjects([url to XML data with SVG objects]); // returns group
XmlDump(); // echos document in XML format.
/* static methods */
TranslateObject ([obj ref|obj group],[position delta object]);
ScaleObject(... );
RotateObject(.. .);
CreateObject([type],[obj relation]);
// obj relation is an optional object which contains a ref to
another svg object and "how" it raltes to the new object.
RelateObject([src objct],[obj relation]);
....
anyway, you get the picture...
You might want to maintain a stack which is an associative array
containing all the created objects so XmlDump() need only walk the
array, serializing objects (and related dependencies) as it goes.
Maybe another stack for groups, maybe not.
You might want to do this with PHP5 as there is a lot of reference
passing going on.
anyway, just an idea in case anyone out there is interested.
Could be fun.