2 //=======================================================================
4 // Description: Simple tool to create a gradient background
6 // Author: Johan Persson (johanp@aditus.nu)
7 // Ver: $Id: mkgrad.php,v 1.1 2002/08/09 23:09:12 aditus Exp $
10 // Copyright (C) 2002 Johan Persson
11 //=======================================================================
14 // This includes a lot of unecessary things as well...
15 include "../../jpgraph.php";
16 include "../../jpgraph_bar.php";
17 include "../../jpgraph_canvas.php";
20 // Must have a global comparison method for usort()
21 function _cmp($a,$b) {
26 // Generate the input form
33 $this->iColors = array_keys($rgb->rgb_table);
34 usort($this->iColors,'_cmp');
36 $this->iGradstyles = array(
39 "Vertical from middle",3,
40 "Horizontal from middle",4,
41 "Horizontal wider middle",6,
42 "Vertical wider middle",7,
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>';
52 echo '<td>Height:<br>'.$this->GenHTMLInput('h',8,4,300).'</td></tr>';
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);
59 echo '<tr><td colspan=2>Gradient style:<br>';
60 echo $this->GenHTMLSelectCode('s',$this->iGradstyles);
62 echo '<tr><td colspan=2>Filename: (empty to stream)<br>';
63 echo $this->GenHTMLInput('fn',55,100);
65 echo '<tr><td colspan=2 align=right>'.$this->GenHTMLSubmit('submit').'</td></tr>';
71 function GenHTMLSubmit($name) {
72 return '<INPUT TYPE=submit name="ok" value=" Ok " >';
76 function GenHTMLInput($name,$len,$maxlen=100,$val='') {
77 return '<INPUT TYPE=TEXT NAME='.$name.' VALUE="'.$val.'" SIZE='.$len.' MAXLENGTH='.$maxlen.'>';
80 function GenHTMLSelect($name,$option,$selected="",$size=0) {
81 $txt="<select name=$name";
83 $txt .= " size=$size >";
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";
90 $txt=$txt."<option value=\"".$option[$i]."\">$option[$i]</option>\n";
92 return $txt."</select>\n";
95 function GenHTMLSelectCode($name,$option,$selected="",$size=0) {
96 $txt="<select name=$name";
98 $txt .= " size=$size >";
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";
105 $txt=$txt."<option value=\"".$option[($i+1)]."\">$option[$i]</option>\n";
107 return $txt."</select>\n";
112 // Basic application driver
116 var $iWidth,$iHeight;
117 var $iFromColor, $iToColor;
122 $this->iForm = new Form();
125 function GenGradImage() {
127 global $HTTP_POST_VARS;
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'];
137 if( $aFrom=='' || $aTo=='' || $aWidth < 1 || $aHeight < 1 )
138 exit("Syntax: mkgrad?w=nnn&h=nnn&fc=fromColor&tc=toColor&s=n");
140 $this->iWidth = $aWidth;
141 $this->iHeight = $aHeight;
142 $this->iFromColor = $aFrom;
143 $this->iToColor = $aTo;
144 $this->iStyle = $aStyle;
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,
154 if( $aFileName != "" ) {
155 $this->graph->Stroke($aFileName);
156 echo "Image file '$aFileName' created.";
159 $this->graph->Stroke();
165 global $HTTP_POST_VARS;
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.
173 if( @$HTTP_POST_VARS['ok']===' Ok ' ) {
174 $this->GenGradImage();
181 $driver = new Driver();