1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
| <?php
header("Content-type: image/svg+xml");
$offsetGauche = 30;
$offsetDroit = 15;
$width = (isset($_GET['width']) ? $_GET['width'] : 240);
$height = (isset($_GET['height']) ? $_GET['height'] : 35);
$prog = (isset($_GET['prog']) ? $_GET['prog'] : '');
$title = (isset($_GET['title']) ? $_GET['title'] : ' ');
$n = intval(($width - $offsetGauche - $offsetDroit) / 24);
$taille = $n * 24;
$font= "verdana";
$fontSize = "10";
$blanc = "white";
$orange = "orange";
$rouge = "red";
$bleuclair = "rgb(124, 182, 236)";
$gris = "gray";
$grisClair = "rgb(192, 192, 192)";
$noir = "black";
$strX = 15;
$strY = 10;
$titleX = 0;
$titleY = 30;
function SvgTxt($x,$y,$str,$size, $color,$fontname, $anchor){
echo <<<oo
<text x="{$x}" y="{$y}"
fill="{$color}"
stroke="none"
font-family="{$fontname}"
font-size="{$size}"
text-anchor="{$anchor}">
{$str}
</text>
oo;
}
function SvgLine($x1,$y1,$x2,$y2, $color){
echo <<<oo
<line x1="{$x1}" y1="{$y1}"
x2="{$x2}" y2="{$y2}"
stroke="{$color}" fill="none" />
oo;
}
function SvgRect($x1,$y1,$x2,$y2, $color){
$w=$x2-$x1;
$h=$y2-$y1;
echo <<<oo
<rect x="{$x1}" y="{$y1}"
width="{$w}"
height="{$h}"
fill="{$color}"
stroke="none" />
oo;
}
// debut
echo <<<oo
<?xml version="1.0"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN"
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<svg xmlns="http://www.w3.org/2000/svg" width="{$width}" height="{$height}">
oo;
for ($i=0; $i<=24; $i++) {
$x = $i*$n+$offsetGauche;
if (($i % 6) == 0) {
// ImageLine($image, $x, 15, $x, 25, $gris);
SvgLine($x, 15, $x, 25, $gris);
if ($i < 12) {
$str = '0' . $i . ':00';
} else {
$str = $i . ':00';
}
//imagefttext($image, $fontSize, $strAngle, $x-$strX, $strY, $noir, $fontfile, $str);
SvgTxt($x , $strY, $str, $fontSize, $noir, $font, "middle");
} else {
// ImageLine($image, $x, 20, $x, 25, $grisClair);
SvgLine($x, 20, $x, 25, $grisClair);
}
}
//imagefttext($image, $fontSize, $titleAngle, $titleX, $titleY, $noir, $fontfile, $title);
SvgTxt($titleX, $titleY, $title, $fontSize, $noir, $font, "start" );
//imagefilledrectangle($image, $offsetGauche, 26, $taille + $offsetGauche, 35, $bleuclair);
SvgRect($offsetGauche,26,$taille + $offsetGauche,35,$bleuclair);
if ($prog !== '') {
$progs = explode(",", $prog);
$n = count($progs);
if (($n % 3) == 0) {
for ($i=0; $i<$n; $i+=3) {
$mode = $progs[$i];
$start = $progs[$i+1];
$end = $progs[$i+2];
$nombres = explode(":", $start);
$debut = $nombres[0] * 60 + $nombres[1];
$debut = $offsetGauche + $taille * $debut / 1440;
$nombres = explode(":", $end);
$fin = $nombres[0] * 60 + $nombres[1];
$fin = $offsetGauche + $taille * $fin / 1440;
if ($mode === 'n') {
// imagefilledrectangle($image, $debut, 26, $fin, 35, $orange);
SvgRect($debut, 26, $fin, 35, $orange);
} else {
// imagefilledrectangle($image, $debut, 26, $fin, 35, $rouge);
SvgRect($debut, 26, $fin, 35, $rouge);
}
}
}
}
echo "</svg>";
?> |
Partager