3
header("Content-type: image/png");
6
* @file Background Gradient Image generator
8
* This file create a background gradient image using the gd library. It will return
9
* the image directly and save it on the server for the next time. It will not
10
* generate the same image twice.
12
* I used small portions of code from two web sites:
13
* @see http://www.hawkee.com/snippet/5022/
14
* @see http://ca.php.net/imagecolorresolve
16
* @author David Giard (swe3tdave)
18
* @param start Starting Color
19
* @param end End Color
21
* @return Generated or Cached Image
24
* Use it as you would a normal image, like this:
25
* <img src="gradient.php?start=796646&end=D3CAAA">
26
* Or inside a css file:
27
* background-image: url(gradient.php?start=796646&end=D3CAAA);
32
$default_background = "background.png";
33
$default_start_color = '796646';
34
$default_end_color = 'D3CAAA';
35
$default_image_path = ''; // Default to script directory
38
* Changing those will change how the gradient curve is generated. So you can try
39
* changing them and see what appends. Here are the default setting in case you
40
* want to change back :
42
* $gradient_start = 65;
43
* $gradient_curve = 1.1;
44
* $gradient_sum = 800 / $gradient_curve;
47
$gradient_curve = 1.1;
48
$gradient_sum = 800 / $gradient_curve;
50
/**************************************************************************************
51
* You shoudn't modify anything behond this point, unless you know what you're doing. *
52
**************************************************************************************/
54
$start = $default_start_color;
55
$end = $default_end_color;
57
$start = $_GET["start"];
63
function _myexactcolor($png, $r, $g, $b) {
64
$mycolor = imagecolorexact($png, $r, $g, $b);
66
$mycolor = imagecolorallocate($png, $r, $g, $b);
69
$mycolor = imagecolorresolve($png, $r, $g, $b);
70
#error_log("Damn! STILL couldn't allocate the color!", 0);
75
function _createnewpng() {
76
global $start, $end, $width, $height, $gradient_curve, $gradient_start, $gradient_sum, $default_image_path;
78
if (!file_exists($default_image_path . $start . "-" . $end . ".png")) {
79
$start_r = hexdec(substr($start, 0, 2));
80
$start_g = hexdec(substr($start, 2, 2));
81
$start_b = hexdec(substr($start, 4, 2));
82
$end_r = hexdec(substr($end, 0, 2));
83
$end_g = hexdec(substr($end, 2, 2));
84
$end_b = hexdec(substr($end, 4, 2));
85
$image = imagecreate($width, $height);
87
$gradient_curve = $gradient_curve + ($start_r*(0.5/121));
89
for($i=0;$i<250;$i++) {
90
$colorset[$i] = _myexactcolor($image, $start_r + ($i*(($end_r-$start_r)/250)), $start_g + ($i*(($end_g-$start_g)/250)), $start_b + ($i*(($end_b-$start_b)/250)));
92
for($y=0;$y<$height;$y++) {
93
for($x=0;$x<$width;$x++) {
95
if ($y<=$gradient_start) {
96
imagesetpixel ($image, $x, $y, $colorset[0] );
99
imagesetpixel ($image, $x, $y, $colorset[(int)(((pow($y - $gradient_start, ($gradient_sum / ($y- $gradient_start))) * 250 * pow($height - $gradient_start, 0 - ($gradient_sum / ($y- $gradient_start)))) + (pow($y - $gradient_start, $gradient_curve)* 250 *pow($height - $gradient_start, 0-$gradient_curve)))/2)] );
104
imagepng($image,$default_image_path . $start . "-" . $end . ".png");
106
imagedestroy($image);
109
$h = fopen($default_image_path . $start . "-" . $end . ".png", "r");
116
if ($start != $default_start_color || $end != $default_end_color) {
120
if (file_exists($default_image_path . $default_background)) {
121
$h = fopen($default_image_path . $default_background, "r");
b'\\ No newline at end of file'