3. php-svg avec des librairies svg
3. php-svg avec des librairies svg
technologies internet et education, © tecfa
3. php-svg avec des librairies svg
3. php-svg avec des librairies svg
travailler avec une libraire améliore la flexibilité et le coût de maintenance de votre code. si vous ne trouvez rien qui vous convient, faites la vôtre (au moins quelques fonctions utiles pour les opérations répétitives).
3.1 phphtmllib
http://phphtmllib.newsblob.com/
(site phphtmllib)
http://tecfa.unige.ch/lib/php/phphtmllib/
(installation local à tecfa)
http://tecfa.unige.ch/lib/php/phphtmllib/doc/
(documentation à tecfa)
phphtmllib est une très grande librairie à fonctions multiples
du manuel: phphtmllib is a set of php classes and library functions to build, debug, and render xml, html, xhtml, wap/wml documents, and svg (scalable vector graphics) images as well as complex html 'widgets' for php 4.2 or better.
populaire, de grande qualité, "lourd", nécessite une certaine expertise pour interpréter le manuel
exemple 3-1: exemple svg-phphtmllib simple
http://tecfa.unige.ch/guides/php/examples/svg-phphtmllib/
(phphtmllib-simple.*)
$phphtmllib = $_server["document_root"] . "/lib/php/phphtmllib";
include_once("$phphtmllib/includes.inc");
include_once($phphtmllib."/widgets/svg/svgdocumentclass.inc");
//0. create a page object with dimensions
$svgpage = new svgdocumentclass(800,600);
//1. add a nice rectangle
$rect = svg_rect(50,50,600,400,"none","black",3);
//2. add polyline
$line = "50,375 150,375 150,325 250,325 250,375 350,375 350,250 450,250 450,375 550,375 550,175 600,175";
$zoliline = svg_polyline($line,"none","blue","2");
//3. add an ellipse
$oeuf = svg_ellipse(300,300,200,100,"red","black","1");
//4. add these objects to the page object
$svgpage->add($rect);
$svgpage->add($oeuf);
$svgpage->add($zoliline);
//5. render the whole thing
print $svgpage->render();
exemple 3-2: exemple svg-phphtmllib svgxylinegraph
http://tecfa.unige.ch/guides/php/examples/svg-phphtmllib/
(svgxylinegraph.*)
cet exemple utilise un widget pour faire des "line graphs"
pour la documentation voir la classe svgxylinegraph (y compris méthodes héritées)
.....
$width = 500;
$height = 500;
$svgdoc = new svgdocumentclass("100%","100%");
$graph = new svgxylinegraph("popularity/usage/activity of tecfa's php examples", $width,$height);
$graph->set_x_title("x-axis year");
$graph->set_y_title("popularity");
//add three lines with different colors
$graph->add_line("0,1,2.3,4.2,6,8", "1,2,2.7,0.3,6,1", "red");
$graph->add_line("0,1,4.1,6", "0,4,2,3", "blue");
$graph->add_line("0,1,2,3,4,5,7", "0,4,3,1,7,8,10", "black");
//add the line graph widget to the document.
$svgdoc->add( $graph );
print $svgdoc->render();
3.2 svg class de killian
http://www.phpclasses.org/browse.html/package/457.html
cette classe semble etre très bien faite (avec un petit volume)
mais elle vient sans aucune documentation (il faut regarder le code)
exemple 3-3: exemple d'animation avec svg class
http://tecfa.unige.ch/guides/php/examples/svg-class
(svgclass-example.php)
// *** define the path to the svg class dir. ***
define("svg_class_base", "./ori/");
// include the class files.
require_once(svg_class_base."svg.php");
// create an instance of svgdocument. all other objects will be added to this
// instance for printing. also set the height and width of the viewport.
$svg =& new svgdocument("400", "400");
// 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.
$g->addparent($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",
"freeze"));
// once the circle is created move it right and down // dks addition
$circle->addchild(new svganimate("cx", "xml", "", "200", "4s", "3s", "freeze"));
$circle->addchild(new svganimate("cy", "xml", "", "200", "4s", "3s", "freeze"));
// make the circle a child of g.
$g->addchild($circle);
// create and animate some text.
$text = new svgtext("0", "0", "svg is cool",
"font-size:20;text-anchor:middle;", "");
$text->addchild(new svganimate("font-size", "auto", "0", "20", "", "3s",
"freeze"));
// make the text a child of g.
$g->addchild($text);
// send a message to the svg instance to start printing.
$svg->printelement()
-- tie
3. php-svg avec des librairies svg
Précédent 786 Précédent 785 Précédent 784 Précédent 783 Précédent 782 Précédent 781 Précédent 780 Précédent 779 Précédent 778 Précédent 777 Précédent 776 Précédent 775 Précédent 774 Précédent 773 Précédent 772 Précédent 771 Précédent 770 Précédent 769 Précédent 768 Précédent 767 Précédent 766 Précédent 765 Précédent 764 Précédent 763 Précédent 762 Précédent 761 Précédent 760 Précédent 759 Précédent 758 Précédent 757 Suivant 788 Suivant 789 Suivant 790 Suivant 791 Suivant 792 Suivant 793 Suivant 794 Suivant 795 Suivant 796 Suivant 797 Suivant 798 Suivant 799 Suivant 800 Suivant 801 Suivant 802 Suivant 803 Suivant 804 Suivant 805 Suivant 806 Suivant 807 Suivant 808 Suivant 809 Suivant 810 Suivant 811 Suivant 812 Suivant 813 Suivant 814 Suivant 815 Suivant 816 Suivant 817