By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,825 Members | 1,258 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,825 IT Pros & Developers. It's quick & easy.

SVG Api in PHP

P: n/a
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.

--
Karthik
Humans please 'removeme_' for my real email.
Jul 17 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
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?

Jul 17 '05 #2

P: n/a
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).

--
Karthik
Humans please 'removeme_' for my real email.
Jul 17 '05 #3

P: n/a
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|circle],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.
Jul 17 '05 #4

P: n/a
Karthik <re*******************@yahoo.com> wrote in message news:<409651c9$1@darkstar>...
Terence wrote:
Karthik wrote:

<snip>
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

Tried this <http://pear.php.net/package/XML_SVG/> ??

--
| Just another PHP saint |
Email: rrjanbiah-at-Y!com
Jul 17 '05 #5

P: n/a
Terence <tk******@fastmail.fm> wrote in message news:<4096fa3b$1@herald>...
Karthik wrote: <snip> 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();
[..]
anyway, just an idea in case anyone out there is interested.
Could be fun.


No need to reinvent... <http://www.phpclasses.org/svg> (dated 2002-02-16)

--
| Just another PHP saint |
Email: rrjanbiah-at-Y!com
Jul 17 '05 #6

P: n/a
"Karthik" <re*******************@yahoo.com> schrieb im Newsbeitrag
news:409651c9$1@darkstar...
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).


I still don't understand what you want to do:
- Analyze SVG with PHP and convert it to anything else (i.e. Gif)?
- Write SVG graphic with PHP (could be an extension to the GD lib)?

The rendering (as you wrote in your first post) is definitely done at the
client side so has nothing to do with PHP.

--
Markus
Jul 17 '05 #7

P: n/a
Markus Ernst wrote:

- Analyze SVG with PHP and convert it to anything else (i.e. Gif)?
- Write SVG graphic with PHP (could be an extension to the GD lib)?>
The rendering (as you wrote in your first post) is definitely done at the
client side so has nothing to do with PHP.


Oops ! I actually meant to generate the SVG documents at the server
side using a simple API. Sorry for the wrong usage of the word -
'rendering' . It is out of context, i admit. Thanks for pointing it out.

--
Karthik.
Humans please 'removeme_' for my real email.
Jul 17 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.