SVG Api in PHP

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Karthik

    SVG Api in PHP

    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.
  • Terence

    #2
    Re: SVG Api in PHP

    Karthik wrote:
    [color=blue]
    > 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.
    >[/color]

    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?

    Comment

    • Karthik

      #3
      Re: SVG Api in PHP

      Terence wrote:[color=blue]
      > Karthik wrote:
      >[color=green]
      >> 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.
      >>[/color]
      >
      > 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?
      >[/color]
      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.

      Comment

      • Terence

        #4
        Re: SVG Api in PHP

        Karthik wrote:
        [color=blue]
        > Terence wrote:
        >[color=green]
        >> Karthik wrote:
        >>[color=darkred]
        >>> 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.
        >>>[/color]
        >>
        >> 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?
        >>[/color]
        > 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).
        >[/color]

        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.

        Comment

        • R. Rajesh Jeba Anbiah

          #5
          Re: SVG Api in PHP

          Karthik <removeme_kayka ydreamz@yahoo.c om> wrote in message news:<409651c9$ 1@darkstar>...[color=blue]
          > Terence wrote:[color=green]
          > > Karthik wrote:[/color][/color]

          <snip>
          [color=blue]
          > 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[/color]


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

          --
          | Just another PHP saint |
          Email: rrjanbiah-at-Y!com

          Comment

          • R. Rajesh Jeba Anbiah

            #6
            Re: SVG Api in PHP

            Terence <tk.lists@fastm ail.fm> wrote in message news:<4096fa3b$ 1@herald>...[color=blue]
            > Karthik wrote:[/color]
            <snip>[color=blue]
            > 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();[/color]

            [..]
            [color=blue]
            > anyway, just an idea in case anyone out there is interested.
            > Could be fun.[/color]

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

            --
            | Just another PHP saint |
            Email: rrjanbiah-at-Y!com

            Comment

            • Markus Ernst

              #7
              Re: SVG Api in PHP

              "Karthik" <removeme_kayka ydreamz@yahoo.c om> schrieb im Newsbeitrag
              news:409651c9$1 @darkstar...[color=blue]
              > 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).[/color]

              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


              Comment

              • Karthik

                #8
                Re: SVG Api in PHP

                Markus Ernst wrote:

                [color=blue]
                > - 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.
                >[/color]

                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.

                Comment

                Working...