-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathgradient.php
215 lines (160 loc) · 5.43 KB
/
gradient.php
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
<?php
include "globals.php";
print"<h3>BBCode Gradient Text Generator</h3>";
function prepareGradien($hexstart, $hexend, $sentence)
{
$steps = strlen($sentence);
$start['r'] = hexdec(substr($hexstart, 0, 2));
$start['g'] = hexdec(substr($hexstart, 2, 2));
$start['b'] = hexdec(substr($hexstart, 4, 2));
$end['r'] = hexdec(substr($hexend, 0, 2));
$end['g'] = hexdec(substr($hexend, 2, 2));
$end['b'] = hexdec(substr($hexend, 4, 2));
$step['r'] = ($start['r'] - $end['r']) / ($steps);
$step['g'] = ($start['g'] - $end['g']) / ($steps);
$step['b'] = ($start['b'] - $end['b']) / ($steps);
$gradien = array();
for($i = 0; $i < $steps; $i++)
{
$rgb['r'] = floor($start['r'] - ($step['r'] * $i));
$rgb['g'] = floor($start['g'] - ($step['g'] * $i));
$rgb['b'] = floor($start['b'] - ($step['b'] * $i));
$hex['r'] = sprintf('%02x', ($rgb['r']));
$hex['g'] = sprintf('%02x', ($rgb['g']));
$hex['b'] = sprintf('%02x', ($rgb['b']));
$gradien[] = implode(NULL, $hex);
}
$letters = array();
for($i = 0; $i < $steps; $i++)
{
$letters[] = $sentence{$i};
}
$grad = array();
for($j = 0; $j < $steps; $j++)
{
$grad[$gradien[$j]] = $letters[$j];
}
return $grad;
}
function gradien($hexstart, $hexend, $sentence)
{
$gradien = prepareGradien($hexstart, $hexend, $sentence);
foreach($gradien as $key => $value)
{
$value = str_replace('&','&',$value);
$value = str_replace('<','<',$value);
$value = str_replace('>','>',$value);
print"[color=#".$key."]".$value."[/color]";
}
}
function prepareGradie($hexstart, $hexend, $sentence)
{
$steps = strlen($sentence);
$start['r'] = hexdec(substr($hexstart, 0, 2));
$start['g'] = hexdec(substr($hexstart, 2, 2));
$start['b'] = hexdec(substr($hexstart, 4, 2));
$end['r'] = hexdec(substr($hexend, 0, 2));
$end['g'] = hexdec(substr($hexend, 2, 2));
$end['b'] = hexdec(substr($hexend, 4, 2));
$step['r'] = ($start['r'] - $end['r']) / ($steps);
$step['g'] = ($start['g'] - $end['g']) / ($steps);
$step['b'] = ($start['b'] - $end['b']) / ($steps);
$gradie = array();
for($i = 0; $i < $steps; $i++)
{
$rgb['r'] = floor($start['r'] - ($step['r'] * $i));
$rgb['g'] = floor($start['g'] - ($step['g'] * $i));
$rgb['b'] = floor($start['b'] - ($step['b'] * $i));
$hex['r'] = sprintf('%02x', ($rgb['r']));
$hex['g'] = sprintf('%02x', ($rgb['g']));
$hex['b'] = sprintf('%02x', ($rgb['b']));
$gradie[] = implode(NULL, $hex);
}
$letters = array();
for($i = 0; $i < $steps; $i++)
{
$letters[] = $sentence{$i};
}
$grad = array();
for($j = 0; $j < $steps; $j++)
{
$grad[$gradie[$j]] = $letters[$j];
}
return $grad;
}
function gradie($hexstart, $hexend, $sentence)
{
$gradie = prepareGradie($hexstart, $hexend, $sentence);
foreach($gradie as $key => $value)
{
$value = str_replace('&','&',$value);
$value = str_replace('<','<',$value);
$value = str_replace('>','>',$value);
print"<b><font color='#".$key."'>".$value."</font></b>";
}
}
print "<form action='gradient.php' method='post'>
<input type=hidden name=submit value=1>
<select class=textbox name='start'>
<option value='0'>Select Start Color</option>
<option value='ff0000'>Red</option>
<option value='ffffff'>White</option>
<option value='ffff00'>Yellow</option>
<option value='0000ff'>Blue</option>
<option value='FF1493'>Pink</option>
<option value='696969'>Grey</option>
<option value='00ff00'>Lime</option>
<option value='E9967A'>Salmon</option>
<option value='9932CC'>Purple</option>
<option value='FFA500'>Orange</option>
<option value='40E0D0'>Turquoise</option>
</select>
<select class=textbox name='stop'>
<option value='0'>Select End Color</option>
<option value='ff0000'>Red</option>
<option value='ffffff'>White</option>
<option value='ffff00'>Yellow</option>
<option value='0000ff'>Blue</option>
<option value='FF1493'>Pink</option>
<option value='696969'>Grey</option>
<option value='00ff00'>Lime</option>
<option value='E9967A'>Salmon</option>
<option value='9932CC'>Purple</option>
<option value='FFA500'>Orange</option>
<option value='40E0D0'>Turquoise</option>
</select>
<br /><br />
<font color='red'><b>Enter the Text you wish to Convert</b></font><br />
<input type='text' STYLE='color: black; background-color: white;' name='text' maxlength='40' length='40' /><br /><font color='red'>Maximum of 40 Characters</font><br />
<input type='submit' STYLE='color: black; background-color: white;' value='Convert to BBCode' />
</form><br />";
if($_POST['submit'])
{
if ($_POST['start'] == $_POST['stop'])
{
print "The Start color and End color cannot be the same";
$h->endpage();
exit;
}
if (strlen($_POST['text']) > 40)
{
print "Stop trying to abuse the game!!!";
$h->endpage();
exit;
}
if($_POST['text'] == "")
{
print "You did not enter any text.";
}
else
{
print"<textarea rows=5 cols=100>";
gradien($_POST['start'], $_POST['stop'], $_POST['text']);
print"</textarea><br />";
print"<br /><table class='table' width='75%'><tr><th>Your Text will look like this</th></tr><tr><td>";
gradie($_POST['start'], $_POST['stop'], $_POST['text']);
print"</td></tr></table>";
}
}
$h->endpage();
?>