]> git.llucax.com Git - mecon/meconlib.git/blob - lib/MECON/Graph/external/jpgraph/src/utils/misc/mkgrad.php
Se mejora un poco los ALT para navegadores de texto.
[mecon/meconlib.git] / lib / MECON / Graph / external / jpgraph / src / utils / misc / mkgrad.php
1 <?php
2 //=======================================================================
3 // File:        MKGRAD.PHP
4 // Description: Simple tool to create a gradient background
5 // Created:     2002-08-09
6 // Author:      Johan Persson (johanp@aditus.nu)
7 // Ver:         $Id: mkgrad.php,v 1.1 2002/08/09 23:09:12 aditus Exp $
8 //
9 // License:     QPL 1.0
10 // Copyright (C) 2002 Johan Persson
11 //=======================================================================
12
13
14 // This includes a lot of unecessary things as well...
15 include "../../jpgraph.php";
16 include "../../jpgraph_bar.php";
17 include "../../jpgraph_canvas.php";
18   
19
20 // Must have a global comparison method for usort()
21 function _cmp($a,$b) {
22     return strcmp($a,$b);
23 }
24
25
26 // Generate the input form
27 class Form {
28     var $iColors;
29     var $iGradstyles;
30     function Form() {
31
32         $rgb = new RGB();
33         $this->iColors = array_keys($rgb->rgb_table);
34         usort($this->iColors,'_cmp');
35
36         $this->iGradstyles = array(
37             "Vertical",2,
38             "Horizontal",1,
39             "Vertical from middle",3,
40             "Horizontal from middle",4,
41             "Horizontal wider middle",6,
42             "Vertical wider middle",7,
43             "Rectangle",5 );
44     }
45
46     function Run() {
47
48         echo '<h3>Generate gradient background</h3>';
49         echo '<form METHOD=POST action=""><table style="border:blue solid 1;">';
50         echo '<tr><td>Width:<br>'.$this->GenHTMLInput('w',8,4,300).'</td>';
51         echo "\n";
52         echo '<td>Height:<br>'.$this->GenHTMLInput('h',8,4,300).'</td></tr>';
53         echo "\n";
54         echo '<tr><td>From Color:<br>';
55         echo $this->GenHTMLSelect('fc',$this->iColors);
56         echo '</td><td>To Color:<br>';
57         echo $this->GenHTMLSelect('tc',$this->iColors);
58         echo '</td></tr>';
59         echo '<tr><td colspan=2>Gradient style:<br>';
60         echo $this->GenHTMLSelectCode('s',$this->iGradstyles);
61         echo '</td></tr>';
62         echo '<tr><td colspan=2>Filename: (empty to stream)<br>';
63         echo $this->GenHTMLInput('fn',55,100);
64         echo '</td></tr>';
65         echo '<tr><td colspan=2 align=right>'.$this->GenHTMLSubmit('submit').'</td></tr>';
66         echo '</table>';
67         echo '</form>';
68
69     }
70
71     function GenHTMLSubmit($name) {
72         return '<INPUT TYPE=submit name="ok"  value=" Ok " >';
73     }
74
75
76     function GenHTMLInput($name,$len,$maxlen=100,$val='') {
77         return '<INPUT TYPE=TEXT NAME='.$name.' VALUE="'.$val.'" SIZE='.$len.' MAXLENGTH='.$maxlen.'>';
78     }
79
80     function GenHTMLSelect($name,$option,$selected="",$size=0) {
81         $txt="<select name=$name";
82         if( $size > 0 )
83             $txt .= " size=$size >";
84         else 
85             $txt .= ">";
86         for($i=0; $i<count($option); $i++) {
87             if( $selected==$option[$i] )
88                 $txt=$txt."<option selected value=\"$option[$i]\">$option[$i]</option>\n";              
89             else
90                 $txt=$txt."<option value=\"".$option[$i]."\">$option[$i]</option>\n";
91         }
92         return $txt."</select>\n";
93     }
94     
95     function GenHTMLSelectCode($name,$option,$selected="",$size=0) {
96         $txt="<select name=$name";
97         if( $size > 0 )
98             $txt .= " size=$size >";
99         else 
100             $txt .= ">";
101         for($i=0; $i<count($option); $i += 2) {
102             if( $selected==$option[($i+1)] )
103                 $txt=$txt."<option selected value=".$option[($i+1)].">$option[$i]</option>\n";          
104             else
105                 $txt=$txt."<option value=\"".$option[($i+1)]."\">$option[$i]</option>\n";
106         }
107         return $txt."</select>\n";
108     }
109
110 }
111
112 // Basic application driver
113
114 class Driver {
115     var $iGraph, $iGrad;
116     var $iWidth,$iHeight;
117     var $iFromColor, $iToColor;
118     var $iStyle;
119     var $iForm;
120
121     function Driver() {
122         $this->iForm = new Form();
123     }
124
125     function GenGradImage() {
126
127         global $HTTP_POST_VARS;
128         
129         $aWidth  = (int)@$HTTP_POST_VARS['w'];
130         $aHeight = (int)@$HTTP_POST_VARS['h'];
131         $aFrom   = @$HTTP_POST_VARS['fc'];
132         $aTo     = @$HTTP_POST_VARS['tc'];
133         $aStyle  = @$HTTP_POST_VARS['s'];
134         $aFileName  = @$HTTP_POST_VARS['fn'];
135
136
137         if( $aFrom=='' || $aTo=='' || $aWidth < 1 || $aHeight < 1 )
138             exit("Syntax: mkgrad?w=nnn&h=nnn&fc=fromColor&tc=toColor&s=n");
139
140         $this->iWidth     = $aWidth;
141         $this->iHeight    = $aHeight;
142         $this->iFromColor = $aFrom;
143         $this->iToColor   = $aTo;
144         $this->iStyle     = $aStyle;
145
146         $this->graph = new CanvasGraph($aWidth,$aHeight);
147         $this->grad  = new Gradient($this->graph->img);
148         $this->grad->FilledRectangle(0,0,
149                                      $this->iWidth,$this->iHeight,
150                                      $this->iFromColor,
151                                      $this->iToColor,
152                                      $this->iStyle);
153
154         if( $aFileName != "" ) {
155             $this->graph->Stroke($aFileName);
156             echo "Image file '$aFileName' created.";
157         }
158         else
159             $this->graph->Stroke();
160     }
161
162
163     function Run() {
164         
165         global $HTTP_POST_VARS;
166
167         // Two modes:
168         // 1) If the script is called with no posted arguments
169         // we show the input form.
170         // 2) If we have posted arguments we naivly assume that
171         // we are called to do the image.
172
173         if( @$HTTP_POST_VARS['ok']===' Ok ' ) { 
174             $this->GenGradImage();
175         }
176         else
177             $this->iForm->Run();
178     }
179 }
180
181 $driver = new Driver();                         
182 $driver->Run();
183
184 ?>