SVG: Difference between revisions

The educational technology and digital learning wiki
Jump to navigation Jump to search
mNo edit summary
 
(35 intermediate revisions by 2 users not shown)
Line 4: Line 4:
{{quotation | SVG is a language for describing two-dimensional graphics and graphical applications in XML. SVG 1.1 is a W3C Recommendation and forms the core of the current SVG developments. SVG 1.2 is the specification currently being developed as is available in draft form [...]. The SVG Mobile Profiles: SVG Basic and SVG Tiny are targeted to resource-limited devices and are part of the 3GPP platform for third generation mobile phones. SVG Print is a set of guidelines to produce final-form documents in XML suitible for archiving and printing.}} ([http://www.w3.org/Graphics/SVG/ Scalable Vector Graphics (SVG)], retrieved 12:49, 14 March 2007 (MET)).
{{quotation | SVG is a language for describing two-dimensional graphics and graphical applications in XML. SVG 1.1 is a W3C Recommendation and forms the core of the current SVG developments. SVG 1.2 is the specification currently being developed as is available in draft form [...]. The SVG Mobile Profiles: SVG Basic and SVG Tiny are targeted to resource-limited devices and are part of the 3GPP platform for third generation mobile phones. SVG Print is a set of guidelines to produce final-form documents in XML suitible for archiving and printing.}} ([http://www.w3.org/Graphics/SVG/ Scalable Vector Graphics (SVG)], retrieved 12:49, 14 March 2007 (MET)).


See also [[Flash]], a proprietary and "opaque" format.
See also  
* [[SVG links]] (nothing but links, e.g. read this if you look for tools and other resources !)
* [[Using SVG with HTML5 tutorial]]
* [[Static SVG tutorial]]
* [[SVG/SMIL animation tutorial]]
* [[Flash]] (a proprietary and "opaque" format), and [[Adobe FXG]] (Adobe's exchange format between Flash/Flex and other creative Suite programs).


== Application areas ==
== Application areas ==


=== Visualizations ===
''' Visualizations '''


* The biggest market niche is in our opinion visualization.
The biggest market niche was in our opinion, up to 2011, [[visualization]].
; Examples:
* Romain Sauvain made SVG-based links visualization module for this wiki. See the link in the toolbox to your left or read the short [[Mediawiki SvGViz extension]] documentation. Admire the beauty of links! Works with Firefox, Opera or IE with an SVG plugin.
* There is also a "heavier" visualization with a Java Applet made by Urs Richle


== Tools ==
''' Clipart exchange '''


=== Editors ===
SVG is also very popular as an exchange language. E.g. the only decent clipart repository, i.e. the [http://openclipart.org/ Open Clip Art Library], relies on SVG Clip Art. Wikipedia also strongly suggests to upload graphics as SVG files. For the moment, these are rendered as cached bitmaps (since the IE production browser as of 2010 didn't support SVG).


* You can hand code SVG with any [[XML editor]]
Google docs stores graphics directly in SVG and its built-in drawing tool produces SVG. For IE users, Google implemented a JavaScript library that can render the supported subset of SVG.
* [http://inkscape.org/ Inkscape] (Inkscape targets SVG 1.1 therefore some code will not show in Adobe SVG. Also, it doesn't support SMIL animation or DOM scripting)


=== Viewers ===
''' HTML 5 embedded vector graphics '''


* [http://www.mozilla.com/ Firefox] since version 1.5 includes by default a native SVG, but it does not implement SMIL animation tags. Some other static SVG features are missing too, but DOM/Javascript is implemented.
Finally, HTML 5 made SVG into a main stream technology. SVG is '''part of SVG'''. Even Microsoft (IE9) provides support (SMIL animation tags are missing though and should be implemented in a next version)


* [http://www.adobe.com/svg/ Adobe SVG Viewer], works with IE and Firefox. Implements all of SVG 1.0.
''' SVG icons for software '''
** Getting it to work with IE 7 is quite a nightmare. Try the procedure in [http://pilat.free.fr/ie7/index.htm Utilisateurs d'Internet Explorer 7]


* [http://www.emiasys.net/ Renesis], Beta 0.7 in July 2007. Download is for Win. Works standalone and as IE plugin. The SVG visualization of this wiki more or less works with Beta 0.7 + IE7. Colors are missing and SVG links don't work really. The amazing bug is however that this combo only works for embedded SVGs, not with a simple SVG file for which you have to use the standalone player (maybe some installation issue ?). Renesis in the current version doesn't seem to implement SMIL tags, hopefully they will implement these, since Firefox won't have them for a while. - [[User:Daniel K. Schneider|Daniel K. Schneider]] 15:24, 4 July 2007 (MEST).
Many open source programs use icons that are made in SVG, e.g. the Ubuntu desktop


* There are other viewers.
''' Interactive multimedia '''


=== On-line tools ===
SVG graphics have about the same power as Flash graphics. However, since there are no authoring tools, SVG is less popular popular in that area. On the other hand, HTML5 propaganda sites now include many interesting dynamic and interactive applications made with SVG (including games). At some point there will be high-end authoring tools. As of Jan 2013, Flash CS3 can output some kind of HTML5 that requires some extra tweaking.


* [http://validator.w3.org W3C Validator]
== Integration ==


== Links ==
=== HTML5 integration though inlining ===


=== Standards ===
SVG is part of the HTML 5 draft specification. We have seen it working since Chrome 9 and 10, Firefox 4, Opera 11 and Internet Explorer 9 (feb 2011). As of 2014, nearly every browser does support static SVG quite nicely. SVG animations (SMIL) don't work always as expected.


* [http://www.w3.org/TR/SVG/ The official SVG specification]
Below is an example:
* [http://www.w3.org/TR/SVGMobile/  Mobile SVG Profiles: SVG Tiny and SVG Basic] W3C Recommendation 14 January 2003 (SVG on the road !)
* [http://www.w3.org/TR/smil-animation/ SMIL animation] SVG has incorporated SMIL-type animations (a superset). This means that SMIL tutorials will also be useful to you.
* [http://www.w3.org/TR/2001/REC-SVG-20010904/ecmascript-binding.html ECMAScript Language Binding for SVG] (just SVG specific stuff, SVGElement has all the properties and methods of dom::Element !)
* [http://www.w3.org/TR/sXBL/ sXBL], SVG's XML Binding Language (sXBL) s a mechanism for defining the presentation and interactive behavior of elements described in a namespace other than SVG's. (This will allow definition of high-level tagsets). [9/2004]


=== Manuals ===
<source lang="xml">
<!DOCTYPE html>
<html>
  <head>
    <title>HTML5 SVG demo</title>
  </head>


* [http://pilat.free.fr//js_svg/js_dom.php3 Javascript DOM and SVG] database (from Pilat)
  <body>
* See also, the specifications above :)
    <h1>HTML5 SVG Demo</h1>


=== Example sites ===
A nice green circle:
    <svg id="circle" height="200" xmlns="http://www.w3.org/2000/svg">
      <circle id="greencircle" cx="30" cy="30" r="30" fill="green" />
    </svg>


* [http://www.learnsvg.com/ LearnSVG]. Good sample extracts from the Learn ''SVG: The Web Graphics Standard" by Jon Frost, Stefan Goessner and Michel Hirtzler'' book. Revisited by Robert DiBlasi and Tobias Reif
    <hr>
* [http://www.datenverdrahten.de/svglbc/ SVG - Learning By Coding] Site with many very nice examples including advanced topics (in German), easy browsing and looking at code.
    <address>Created by DKS. This is free code</address>
* [http://croczilla.com/svg/ Mozilla SVG resources] has a good list of examples, in particular XHTML/SVG integration and DOM scriptin
  </body>
* [http://pilat.free.fr/ Pilat] Several kinds of examples (e.g. SVG/Javascript, complex applications, [http://pilat.free.fr/english/index.htm SVG compontents]).
</html>
</source>


=== Tutorials ===
The live example is [http://tecfa.unige.ch/guides/svg/ex/html5/circle.html here]. If nothing shows, then your browser is old.


; Basic Tutorials
See the [http://caniuse.com/svg-html5 When can I use Inline SVG in HTML5?] compatibility table at caniuse.com.


* [http://pilat.free.fr/ Pilat] Several tutorials + examples + complex applications.
=== HTML5 integration with other methods ===
* [http://tecfa.unige.ch/staf/staf-g/sierra/staf2x/sitesvg.htm cours SVG de 2 jours (in french)] made by E.Sierra and M-A Thibaut 2003 ("learning by teaching")
* [http://tecfa.unige.ch/guides/tie/html/svg-intro/svg-intro.html Introduction à SVG] (my own slides)
* [http://tecfa.unige.ch/staf/staf-g/nova/staf2x/svg/programme.html 2 day SVG course in french] made by N. Nova and Y. Grassioulet 2002 ("learning by teaching")
* [http://www.xml.com/pub/a/2001/03/21/svg.html An Introduction to Scalable Vector Graphics] by J.D. Eisenberg, XML.com, 2001.
* [http://www.webreference.com/authoring/languages/svg/intro/ Scalable Vector Graphics: The Art is in the Code] Eddie Traversa, Webreference
* [http://www.adobe.com/svg/illustrator/interactivity_palette/index2.html Developer tutorials (incl. Dynamic SVG with JavaScript)], part of adobe's illustrator/svg zone
* [http://www.kevlindev.com KevLindeV] Kevin Lindev's SVG site (tutorials and examples)
* [http://www.webreference.com/xml/column49/ SVG - Open for Business], a (short) webreference.com tutorial
* [http://www.oreilly.com/catalog/svgess/chapter/ch03.html Basic Shapes], chapter three of David Eisenberg's "SVG Essentials" O'Reilly book.
* [http://www-106.ibm.com/developerworks/xml/library/x-svgint/ Add interactivity to your SVG] by Brian John Venn, IBM developperworks article, Aug 2003. Good introductory tutorial.


; SMIL Animation (curently not supported by native Firefox SVG)
You also can use the ''embed'', the ''inline'' or the ''src'' tag.


* [http://www.xml.com/lpt/a/2002/01/23/svg/index.html Digging Animation], by Antoine Quint, XML.com, 2002 (SMIL animation).
See [[Using SVG with HTML5 tutorial]]
* [http://www.topxml.com/snippetcentral/main.asp?view=viewsnippet&lang=codelib&id=v20020625120600 Rotate an SVG shape over it's center], By Pedro Gil, at TopXML, 2002. Shows how to use the rotate parameters.


; Server-side SVG
=== XHTML integration ===


* [http://developpeur.journaldunet.com/tutoriel/php/021205php_svg1a.shtml Combiner SVG avec PHP] JDNet développeurs article de Xavier Boerderie 12/2002.
One of the advantages of SVG is integration with other XML formats. E.g. with older browsers like Firefox or Opera (not IE 7 that did neither support XHTML nor SVG) you can easily mix SVG with XHTML. It now (2014) should work in all browsers. However, ''XHTML as XML'' was never really used due to Microsoft's difficulty to implement XHTML. In other words the W3C' concept of the future Web where various XML languages should mix within a page is dead. [[HTML5]] is the opposite, i.e. a huge monolithic platform made for web applications, i.e. SVG and MathML are '''part''' of HTML5. Integration with XHTML was made in a different more modular spirit ....
* [http://www.roasp.com/ ROASP SVG Portal ]<nowiki>: mostly perl-based server-side ... </nowiki>
* [http://www.zend.com/zend/trick/tricks12apr.php Generating SVG Images with PHP] by L. Atkinson, Zend, 2001. (Pie Chart example)
* [http://www.xml.com/lpt/a/2001/07/11/creatingsvg.html Creating Scalable Vector Graphics with Perl] by K. Hamptom, xml.com, 2001.
* [http://www.carto.net/papers/svg/serverside_svg_php_e.html Example for Serverside SVG generation with PHP] from the excellent carto.net website.
* [http://www.webreference.com/xml/column55/ Google SVG Search] a webreference.com XML column


; Dynamic SVG to/from server + client-side
Below an example
* http://tecfa.unige.ch/guides/svg/ex/svg-intro/hello-svg-within-xhtml.xhtml


(using e.g. Adobe's SVG/DOM extensions)
<source lang="XML" enclose="div">
<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" >


* [http://www.carto.net/papers/svg/samples/get_parse.shtml Example for getURL & parseXML]. The same tutorial gives additional links, e.g. for postURL() that can be used to save data.
<html xmlns="http://www.w3.org/1999/xhtml" 
      xmlns:svg="http://www.w3.org/2000/svg">
<head>
  <title>SVG within XHTML Demo</title>
</head>
<body>


;SVG and XSLT
  <p>You can embed SVG into XHTML, provided that your browser natively implements SVG. E.g. Firefox 1.5 supports most of static SVG.</p>


* [http://surguy.net/articles/client-side-svg.xml Client-side image generation with SVG and XSLT] by Inigo Surguy
  The SVG part starts below <hr />
* [http://www.schemasoft.com/gcatools/gca2html/Output/05-05-02.html Graphical Stylesheets Using XSLT to Generate SVG ]by Mansfield & Fuller, Schema Software. Good article (BROKEN LINK)
* [http://www.xml.com/pub/a/2000/02/16/style/index.html?wwwrrr_20000216.ptxt Component-Based Page Layouts] xml.com article by Didier Martin showing how to embedd SVG in XHTML using XSLT processing
* [http://www-106.ibm.com/developerworks/education/transforming-xml/xmltosvg/index.html Part 2: Transforming XML into SVG ] by Doug Tidwell /@IBM DeveloperWorks (Bar and Pie Charts)
* [http://www.topxml.com/snippetcentral/main.asp?view=viewsnippet&lang=codelib&id=v20020313183135 Using XSLT to produce SVG (3)] by Martin Rowlinson at TopXML (July 2004), Using XSLT to produce a simple pie chart from XML data (source code downloadable too)


=== Various ===
  <svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="400" height="300">
  <!-- un petit rectangle avec des coins arroundis  -->
  <rect x="50" y="50" rx="5" ry="5" width="300" height="100" style="fill:#CCCCFF;stroke:#000099"/>
  <!-- un texte au meme endroit -->
  <text x="55" y="90" style="stroke:#000099;fill:#000099;font-size:24;">
    HELLO cher visiteur
  </text>
  </svg>


* [http://www.w3.org/Graphics/Activity W3C Graphics Activity Statement]. This shows the place of SVG in the overall W3C strategy.
  <hr />
* [http://www.w3.org/Graphics/SVG/Overview.htm8 W3C Scalable Verctor Graphics (SVG)]. This is the overview page (includes News and Pointers)
  The SVG part ended above
* [http://www.xml.com/pub/a/2001/09/12/svg.html Picture Perfect] xml.com, (2001)
</body>
* [http://www.xml.com/pub/a/2003/07/16/svg-prescod.html SVG: A Sure Bet] by Paul Prescod, xml.com (July 2003)
</html>
* [http://www.carto.net/papers/svg/comparison_flash_svg.html Flash and SVG comparison table] (by A. Neumann)
 
* [http://www.sun.com/software/xml/developers/svg/jsp/ JSP Technology and SVG]
</source>
* [http://people.westminstercollege.edu/students/d-b1649/opinions/avoid_flash.html Why to Avoid Flash], by Devin Bunker
 
* [http://www.dack.com/web/flash_evil.html Flash is Evil] by dack (not related to svg but food for thought)
== Generation of SVG with scripts ==
* [http://www.carto.net/papers/svg/index_e.shtml Vector-based Web Cartography: Enabler SVGScalable Vector Graphics] (french & german version also available)
 
* [http://www.math.uoc.gr/%7Eictm2/Proceedings/pap442.pdf SVG - a new dimension in producing interactive netbooks] by Vladimir BATAGELJ and Matjaž ZAVERŠNIK (PDF article). This is an overview paper
SVG can be manipulated and generated with EcmaScript in your browser. However this requires understanding of [[DOM]] programming. Below are some easier methods...
 
=== Creating SVG with PHP ===
 
Producing SVG with PHP is easy. There exist HTML5/SVG libraries. Else you can generate SVG tags yourself. To generate standalone SVG files, you must change the HTTP header as shown below. Else, create HTML5 files with SVG inside ....
 
* http://tecfa.unige.ch/guides/svg/ex/svg-simple/standalone-hello.php
* http://tecfa.unige.ch/guides/svg/ex/svg-simple/standalone-hello.phps
 
<source lang="php" enclose="div">
<?php
//set the content type
header("Content-type: image/svg+xml");
 
//mark this as XML
print('<?xml version="1.0" encoding="iso-8859-1"?>' . "\n");
 
//Point to SVG DTD
print('<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/PR-SVG-20010719/DTD/svg10.dtd">' . "\n");
 
echo "<svg xmlns=\"http://www.w3.org/2000/svg\">\n";
 
print ('<rect x="50" y="50" rx="5" ry="5" width="200" height="100" style="fill:#CCCCFF;stroke:#000099"/>' . "\n");
 
print('<text x="55" y="90" style="stroke:#000099;fill:#000099;fontsize:24;">HELLO cher visiteur </text>' . "\n");
 
print('</svg>' . "\n");
?>
</source>
 
=== SVG generation with XSLT ===
 
Here is an example that works with FireFox and Opera (only a part of the code is shown !). Read more about this topic in the [[XSLT to generate SVG tutorial]]
 
* XML file: http://tecfa.unige.ch/guides/svg/ex/html5-xslt/zero-html5.xml
 
<source lang="xml">
<?xml version="1.0" ?>
<?xml-stylesheet href="zero-html5.xsl" type="text/xsl" ?>
 
<thing>
  <height>50</height>
  <width>100</width>
</thing>
</source>
 
* XSLT File: http://tecfa.unige.ch/guides/svg/ex/html5-xslt/zero-html5.xsl
 
<source lang="xml">
<?xml version="1.0"?>
 
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/2000/svg"
>
<xsl:output
    method="xml"
    doctype-system="about:legacy-compat"
    omit-xml-declaration = "yes"
    encoding="UTF-8"
    indent="yes" />
 
  <xsl:template match="thing">
  <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
      <meta charset="utf-8"></meta>
      <title>XHTML5 + SVG example</title>
    </head>
    <body>
      <p>This line is HTML, embedded SVG is below. Read the <a
      href="http://edutechwiki.unige.ch/en/XSLT_to_generate_SVG_tutorial">
      XSLT to generate SVG tutorial</a></p>
      <svg xmlns="http://www.w3.org/2000/svg" width="200" height="200" >
<rect x="10" y="10" width="{width}"
      height="{height}" fill="red" stroke="black"/> 
      </svg>
    </body>
  </html>
  </xsl:template>
 
</xsl:stylesheet>
</source>
 
=== SVG generation with PHP/XSLT ===
 
<source lang="php" enclose="div">
header("Content-type: image/svg+xml");
error_reporting(E_ALL);
$xml_file = 'travaux.xml';
$xsl_file = 'travaux.xsl';
 
// load the xml file (and test first if it exists)
$dom_object = new DomDocument();
if (!file_exists($xml_file)) exit('Failed to open $xml_file');
$dom_object->load($xml_file);
 
 
// create dom object for the XSL stylesheet and configure the transformer
$xsl_obj = new DomDocument();
if (!file_exists($xsl_file)) exit('Failed to open $xsl_file');
$xsl_obj->load($xsl_file);
$proc = new XSLTProcessor;
$proc->importStyleSheet($xsl_obj); // attach the xsl rules
$html_fragment = $proc->transformToXML($dom_object);
 
print ($html_fragment);
</source>
 
More examples are here: http://tecfa.unige.ch/guides/svg/ex/objects-in-circles/
(some may not work because of a faulty FSS feed I'd have to fix ...)
 
== Links and tools ==
 
See [[SVG links]]
 
For some serious playing around, you can try this online SVG editor. It works with most current browsers (early 2011).
* [http://svg-edit.googlecode.com/svn/tags/stable/editor/svg-editor.html SVG-edit], an online editor implemented in JavaScript


[[Category: XML]]
[[Category: XML]]
[[Category: Multimedia]]
[[Category: web standards]]
[[Category: SVG]]
[[fr:SVG]]

Latest revision as of 19:13, 11 February 2014

Draft

Definition

“SVG is a language for describing two-dimensional graphics and graphical applications in XML. SVG 1.1 is a W3C Recommendation and forms the core of the current SVG developments. SVG 1.2 is the specification currently being developed as is available in draft form [...]. The SVG Mobile Profiles: SVG Basic and SVG Tiny are targeted to resource-limited devices and are part of the 3GPP platform for third generation mobile phones. SVG Print is a set of guidelines to produce final-form documents in XML suitible for archiving and printing.” (Scalable Vector Graphics (SVG), retrieved 12:49, 14 March 2007 (MET)).

See also

Application areas

Visualizations

The biggest market niche was in our opinion, up to 2011, visualization.

Clipart exchange

SVG is also very popular as an exchange language. E.g. the only decent clipart repository, i.e. the Open Clip Art Library, relies on SVG Clip Art. Wikipedia also strongly suggests to upload graphics as SVG files. For the moment, these are rendered as cached bitmaps (since the IE production browser as of 2010 didn't support SVG).

Google docs stores graphics directly in SVG and its built-in drawing tool produces SVG. For IE users, Google implemented a JavaScript library that can render the supported subset of SVG.

HTML 5 embedded vector graphics

Finally, HTML 5 made SVG into a main stream technology. SVG is part of SVG. Even Microsoft (IE9) provides support (SMIL animation tags are missing though and should be implemented in a next version)

SVG icons for software

Many open source programs use icons that are made in SVG, e.g. the Ubuntu desktop

Interactive multimedia

SVG graphics have about the same power as Flash graphics. However, since there are no authoring tools, SVG is less popular popular in that area. On the other hand, HTML5 propaganda sites now include many interesting dynamic and interactive applications made with SVG (including games). At some point there will be high-end authoring tools. As of Jan 2013, Flash CS3 can output some kind of HTML5 that requires some extra tweaking.

Integration

HTML5 integration though inlining

SVG is part of the HTML 5 draft specification. We have seen it working since Chrome 9 and 10, Firefox 4, Opera 11 and Internet Explorer 9 (feb 2011). As of 2014, nearly every browser does support static SVG quite nicely. SVG animations (SMIL) don't work always as expected.

Below is an example:

<!DOCTYPE html>
<html>
  <head>
    <title>HTML5 SVG demo</title>
  </head>

  <body>
    <h1>HTML5 SVG Demo</h1>

A nice green circle:
    <svg id="circle" height="200" xmlns="http://www.w3.org/2000/svg">
      <circle id="greencircle" cx="30" cy="30" r="30" fill="green" />
    </svg>

    <hr>
    <address>Created by DKS. This is free code</address>
  </body>
</html>

The live example is here. If nothing shows, then your browser is old.

See the When can I use Inline SVG in HTML5? compatibility table at caniuse.com.

HTML5 integration with other methods

You also can use the embed, the inline or the src tag.

See Using SVG with HTML5 tutorial

XHTML integration

One of the advantages of SVG is integration with other XML formats. E.g. with older browsers like Firefox or Opera (not IE 7 that did neither support XHTML nor SVG) you can easily mix SVG with XHTML. It now (2014) should work in all browsers. However, XHTML as XML was never really used due to Microsoft's difficulty to implement XHTML. In other words the W3C' concept of the future Web where various XML languages should mix within a page is dead. HTML5 is the opposite, i.e. a huge monolithic platform made for web applications, i.e. SVG and MathML are part of HTML5. Integration with XHTML was made in a different more modular spirit ....

Below an example

<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" >

<html xmlns="http://www.w3.org/1999/xhtml"  
      xmlns:svg="http://www.w3.org/2000/svg">
 <head>
  <title>SVG within XHTML Demo</title>
 </head>
 <body>

  <p>You can embed SVG into XHTML, provided that your browser natively implements SVG. E.g. Firefox 1.5 supports most of static SVG.</p>

  The SVG part starts below <hr />

  <svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="400" height="300">
   <!-- un petit rectangle avec des coins arroundis  -->
   <rect x="50" y="50" rx="5" ry="5" width="300" height="100" style="fill:#CCCCFF;stroke:#000099"/>
   <!-- un texte au meme endroit -->
   <text x="55" y="90" style="stroke:#000099;fill:#000099;font-size:24;">
    HELLO cher visiteur 
   </text>
  </svg>

  <hr />
  The SVG part ended above
</body>
</html>

Generation of SVG with scripts

SVG can be manipulated and generated with EcmaScript in your browser. However this requires understanding of DOM programming. Below are some easier methods...

Creating SVG with PHP

Producing SVG with PHP is easy. There exist HTML5/SVG libraries. Else you can generate SVG tags yourself. To generate standalone SVG files, you must change the HTTP header as shown below. Else, create HTML5 files with SVG inside ....

<?php
//set the content type
header("Content-type: image/svg+xml");

//mark this as XML
print('<?xml version="1.0" encoding="iso-8859-1"?>' . "\n");

//Point to SVG DTD
print('<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/PR-SVG-20010719/DTD/svg10.dtd">' . "\n");

echo "<svg xmlns=\"http://www.w3.org/2000/svg\">\n";

print ('<rect x="50" y="50" rx="5" ry="5" width="200" height="100" style="fill:#CCCCFF;stroke:#000099"/>' . "\n");

print('<text x="55" y="90" style="stroke:#000099;fill:#000099;fontsize:24;">HELLO cher visiteur </text>' . "\n");

print('</svg>' . "\n");
?>

SVG generation with XSLT

Here is an example that works with FireFox and Opera (only a part of the code is shown !). Read more about this topic in the XSLT to generate SVG tutorial

<?xml version="1.0" ?>
<?xml-stylesheet href="zero-html5.xsl" type="text/xsl" ?>

<thing>
  <height>50</height>
  <width>100</width>
</thing>
<?xml version="1.0"?>

<xsl:stylesheet version="1.0" 
		xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
		xmlns="http://www.w3.org/2000/svg"
		>
<xsl:output
     method="xml"
     doctype-system="about:legacy-compat"
     omit-xml-declaration = "yes"
     encoding="UTF-8"
     indent="yes" />
  
  <xsl:template match="thing">
   <html xmlns="http://www.w3.org/1999/xhtml">
     <head>
       <meta charset="utf-8"></meta>
       <title>XHTML5 + SVG example</title>
     </head>
     <body>
       <p>This line is HTML, embedded SVG is below. Read the <a
       href="http://edutechwiki.unige.ch/en/XSLT_to_generate_SVG_tutorial">
       XSLT to generate SVG tutorial</a></p>
       <svg xmlns="http://www.w3.org/2000/svg" width="200" height="200" >
	 <rect x="10" y="10" width="{width}" 
	       height="{height}" fill="red" stroke="black"/>  
       </svg>
     </body>
   </html>
  </xsl:template>
  
</xsl:stylesheet>

SVG generation with PHP/XSLT

header("Content-type: image/svg+xml");
error_reporting(E_ALL);
$xml_file = 'travaux.xml';
$xsl_file = 'travaux.xsl';

 // load the xml file (and test first if it exists)
$dom_object = new DomDocument();
if (!file_exists($xml_file)) exit('Failed to open $xml_file');
$dom_object->load($xml_file);


// create dom object for the XSL stylesheet and configure the transformer
$xsl_obj = new DomDocument();
if (!file_exists($xsl_file)) exit('Failed to open $xsl_file');
$xsl_obj->load($xsl_file);
$proc = new XSLTProcessor;
$proc->importStyleSheet($xsl_obj); // attach the xsl rules
$html_fragment = $proc->transformToXML($dom_object);

print ($html_fragment);

More examples are here: http://tecfa.unige.ch/guides/svg/ex/objects-in-circles/ (some may not work because of a faulty FSS feed I'd have to fix ...)

Links and tools

See SVG links

For some serious playing around, you can try this online SVG editor. It works with most current browsers (early 2011).

  • SVG-edit, an online editor implemented in JavaScript