PHP Classes

File: Example.php

Recommend this page to a friend!
  Classes of Charlie Killian  >  SVG  >  Example.php  >  Download  
File: Example.php
Role: ???
Content type: text/plain
Description: An example showing the SVG classes in use.
Class: SVG
The SVG Class encapsulates the basic SVG elements.
Author: By
Last change:
Date: 19 years ago
Size: 2,564 bytes


Class file image Download
 * Example.php
 * @since 4.1.1
 * To view this example you need a native SVG viewer or plug-in.
 * Try Mozilla or Adobe

// *** Define the path to the SVG class dir. ***

// Include the class files.

// Create an instance of SvgDocument. All other objects will be added to this
// instance for printing.
// Set the height and width of the viewport.
$svg =& new SvgDocument("400", "200");

// Create an instance of SvgGroup.
// Set the style, transforms for child objects.
$g =& new SvgGroup("stroke:black", "translate(200 100)");

// Add a parent to the g instance.
// The same results can be accomplished by making g a child of the svg.

// Create and animate a circle.
$circle = new SvgCircle("0", "0", "100", "stroke-width:3", "");
$circle->addChild(new SvgAnimate("r", "XML", "0", "75", "", "3s", "freeze"));
$circle->addChild(new SvgAnimate("fill", "CSS", "green", "red", "", "3s",

// Make the circle a child of g.

// Create and animate some text.
$text = new SvgText("0", "0", "SVG and PHP",
                    "font-size:20;text-anchor:middle;", "");
$text->addChild(new SvgAnimate("font-size", "auto", "0", "20", "", "3s",

// Make the text a child of g.

// Send a message to the svg instance to start printing.

    The following is outputed:

<?xml version="1.0" encoding="iso-8859-1"? >
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN"
<svg width="400" height="200" xmlns="" xmlns:xlink="" >
<g style="stroke:black" transform="translate(200 100)" >
<circle cx="0" cy="0" r="100" style="stroke-width:3" >
<animate attributeName="r" attributeType="XML" from="0" to="75" dur="3s"
         fill="freeze" />
<animate attributeName="fill" attributeType="CSS" from="green" to="red"
         dur="3s" fill="freeze" />
<text x="0" y="0" style="font-size:20;text-anchor:middle;" >
<animate attributeName="font-size" attributeType="auto" from="0" to="20"
         dur="3s" fill="freeze" />


For more information send a message to info at phpclasses dot org.